You can create functions by defining them.
The syntax is:
def foo(arguments):
...
return output
If you ran the code:
def addNumbers(num1, num2):
return num1+num2
for i in range(4): print(addNumbers(i,i+1))
Python would output:
1
3
5
7
Not all functions need arguments. You can call functions without arguments.
The syntax is:
def foo():
...
return output
If you ran the code:
def pi():
return 3.14
pi()
pi()*3
Python would output:
3.14
9.42
You can declare variables and functions inside functions.
These are called local variables and local functions, respectively.
For local variables:
If you ran the code:
def myFunction(x):
num1 = x**3
num2 = x**(1/2)
return num1-num2
print(myFunction(4))
Python would output:
62.0