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
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 function1(): # outer function
2 print ("Hello from outer function")
3 def function2(): # inner function
4 print ("Hello from inner function")
5 function2()
6
7function1()
8