Functions can have multiple parameters("parameter" being a fancy word for "input"). For example, this substract function accepts 2 parameters a and b
def substract(a,b):
result = a - b
return resultIt's the argument's position that determines which parameter receives it (at least, for now). The first argument goes to the first parameter, the second to the second, and so on. In this example, the subtract function is called with a = 5 and b = 3:
result = subtract(5, 3)
print(result)
# 2Here's an example with four parameters:
def create_introduction(name, age, height, weight):
first_part = "Your name is " + name + " and you are " + age + " years old."
second_part = "You are " + height + " meters tall and weigh " + weight + " kilograms."
full_intro = first_part + " " + second_part
return full_introit can be called like this:
my_name = "John"
my_age = "30"
intro = create_introduction(my_name, my_age, "1.8", "80")
print(intro)
# Your name is John and you are 30 years old. You are 1.8 meters tall and weigh 80 kilograms.Source: boot.dev