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'''
1# Parameter of the function
2# |
3def greetings(Name):
4 #Content inside the function
5 print("Hello",Name)
6 print("How are you",Name)
7print(greetings("Python devloper"))
8# ^
9# |
10# Argument of the function
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 hello(first_name,last_name,age):
2 print("hello",first_name ,last_name)
3 print("ur r",age,"years old")
4 print("nice to meet u")
5
6
7hello("Bro","Code","21")