When we are coding usually see many task repited, that is not a problem but we will have a long code in the future, that can be not readeable or pretty.
For this reason the programing languages include functions, a function is a block of code that perform a especific task, this can receive one or more arguments and work with these for internal operations, all functions return a value.
Example :
user1_name = 'Juan'
user1_age = 23
user2_name = 'Pepe'
user2_age = 18
#Define function and parameters
def gretting(name, age):
#Task to perform
print (f'Hi, your name is {name}')
print (f'Hi, your age is {age}')
# call the function with 2 arguments (user1)
gretting(user1_name, user1_age)
# call the function with 2 arguments (user2)
gretting(user2_name, user2_age)
output :
Hi, your name is Juan
Hi, your age is 23
Hi, your name is Pepe
Hi, your age is 18
Top comments (0)