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
1# declare a function
2def function_name(param) :
3 # content inside a function
4
5function_name(param) # calling function
1# You can make a function by using the [def] keyword
2def foo():
3 print("Hello")
4
5# You can run it by calling it as such
6foo()
7
8def add(numA, numB):
9 print(numA+numB)
10 # or
11 return numA+numB
12
13num = add(1, 5)
14print(num)
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 firstProgram(x):
2 print(x)
3
4firstProgram("Hello, World!")
5# Prints "Hello, World!"