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
1def myFunction(say): #you can add variables to the function
2 print(say)
3
4myFunction("Hello")
5
6age = input("How old are you?")
7
8myFunction("You are {} years old!".format(age))
9
10#this is what you get:
11
12Hello
13How old are you?
14>>11 #lol my real age actually
15You are 11 years old!
1def example(): #This defines it
2 print("Example.") #This is the defined commands
3
4example() #And this is the commands being run
1def test_function(argument1,argument2,argument3) :
2 # Do something with the code, and the arguments.
3 print(argument1)
4 print(argument2)
5 print(argument3)
6
7# Calling the function.
8
9test_function('Hello','World','!')
10
11# Output
12'''
13Hello
14World
15!
16'''
1variable = "Hello, world!" # variable = string("Hello, world!")
2
3#A simply function :
4
5def Functiontest(): #define a function
6 print("Hello, world!")
7 print(variable)
8
9#Function with components :
10
11def Functiontestwithcomponent(arg1, arg2): # Define a function with two arguments, arg1 and arg2.
12 if arg1 == True: # Arguments can have any name, like variables.
13 print(arg2)
14
15#Call a function :
16Functiontest() #Start Function.
17
18#Call a function with two components :
19
20Functiontestwithcomponent(True, "Hello, function!") #Start Function and precise two arguments :
21