Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how do you write a function in python

#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.
 
PREVIOUS NEXT
Tagged: #write #function #python
ADD COMMENT
Topic
Name
5+6 =