24
loading...
This website collects cookies to deliver better user experience
def functionname( parameters ):
"function_docstring"
function_suite
return [expression]
# define a function that says Hello World.
def greet():
print("Hello World")
#calling the function
greet()
#prints> Hello World
def sum(a, b):
return a + b
total = sum(10,20)
print(total)
from fastapi import FastAPI
app = FastAPI()
#Here is the decorator
@app.get("/")
async def root():
return {"message": "Hello World"}
def count_down(start):
""" Count down from a number """
print(start)
def count_down(start):
""" Count down from a number """
print(start)
# call the count_down if the next
# number is greater than 0
next = start - 1
if next > 0:
count_down(next)
count_down(3)
3
2
1
def sum(n):
total = 0
for index in range(n+1):
total += index
return total
result = sum(100)
print(result)
5050
lambda arguments: expression
double = lambda x: x * 2
print(double(5))
#sum of numbers
sum = lambda x: x+5
print(sum(5))
#> 5+5= 10
#multiple args
product = lambda x, y: x*y
print(product(5, 10))
#> 5*10 = 50