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
1OK, basically def function() is a block where you will have one task that you can repeat all over again in the code to make it look short and clean
1# Functions
2
3""" All the functions are followed by the 'def' keyword in python"""
4
5def Greet(User): # The arguments inside the brackets should be called or the function gives you an error
6 print("Hello" + User + "!")
7
8# Calling the function
9
10Greet("Shivram")
11
12# Output: 'Hello Shivram !'
13
1#Functions
2#Functions are followed by the 'def' keyword
3#Name your function
4def myfunc():
5 a = 'This is a func'
6
7#Calling the function
8myfunc()
9print(myfunc())