1#Letters, Nums,
2#& underscores
3#only, can't =7
4#start w/ num | _ 5 is the default value if no
5# | | | value is passed
6# v v v
7def funcName(param1, param2=5): #The colon terminates func header
8 str(param1) #Typecasting is temparary
9 strVar = str(param1) # To make typecast perma, assign to var
10 param1 = param2 # 5 is passed to param1
11 return param1 # 5 is returned
12# ^ ^
13# | |_ return value is optional, if no return value, func
14 #Optional will end returning to func call
15 #return
16
17x = funcName(7)
18print(x) # prints 5
1def function():
2 print('This is a basic function')
3
4function()
5// Returns 'This is a basic function'
6
7def add(numA, numB):
8 print(numA+numB)
9
10add(1,2)
11// Returns 3
12
13def define(value):
14 return value
15
16example = define('Lorem ipsum')
17print(example)
18// Returns 'Lorem ipsum'
19
20
1def name():#name of the def(function);
2 print("Hallo, World!")#Output is Hallo, World!;
3
4name()#Name of the def, the programm will jump to the def;
5
6#output:
7#Hallo, World!
1# Defines Function
2def my_function():
3 print("Hello")
4 print("Bye")
5
6# Calls Function
7my_function()
1# specify the type of arguments and it expected return type
2#(int, str, list...)
3# tis wil make the code easyer to read
4
5def foo(value:int) -> None:
6 print(value)
7
8foo() # run foo
9
10def foo2(value:str) -> str:
11 value += "Hello "
12 print(value)
13 return value
14
15value_of_foo2 = foo2() # run the function and put its return value in a var
16