xxxxxxxxxx
def functionName():
# What to make the function do
# Basic Example
def addNum(num1, num2):
print(num1 + num2)
# To call this function
addNum(2, 4)
# Output: 6
xxxxxxxxxx
#A function is a collection of code, which performs a specific task.
def say_hi(name, age): #This defines the function you can also add
#variables in the parentheses
print("Hello " + name + ", you are " + str(age))
say_hi("Justin", 36) #This calls the function and executes the code
say_hi("Jhon", 38) #Inside the parentheses you can state the name
say_hi("Jason" , 40) #and age that you want to run
#when you are naming a function, name the function with all lowercase.
#If you have a short two word name of your function it is not necessary
#to use a underscore symbol ( _ ), however if you want to there is no
#problem.
xxxxxxxxxx
def example(): #This defines it
print("Example.") #This is the defined commands
example() #And this is the commands being run
xxxxxxxxxx
#plz suscribe my youtube channel --> https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A
# Parameter of the function
# |
def greetings(Name):
#Content inside the function
print("Hello",Name)
print("How are you",Name)
print(greetings("Python devloper"))
# ^
# |
# Argument of the function
xxxxxxxxxx
def test_function(argument1,argument2,argument3) :
# Do something with the code, and the arguments.
print(argument1)
print(argument2)
print(argument3)
# Calling the function.
test_function('Hello','World','!')
# Output
'''
Hello
World
!
'''
xxxxxxxxxx
#to create a function in python, do the following
#create func
def func(): #can add variables inside the brackets
print("This is the function of the func")
# to call a function, do the following
func()
#you would get a line of code saying "This is the function of the func"
# By Codexel
xxxxxxxxxx
def add(number):
equation = 5 + number
print(equation)
add(10)
output:
15
xxxxxxxxxx
# defining a function
def my_func():
print("Greetings User! Welcome to Softhunt.net")
# calling the function
my_func()
xxxxxxxxxx
def function_name():
# write here what the function does
print("my first function")
function_name() # call the function