parameters. So, we pass arguments to a function and the function accepts parameters.
How to pass multiple arguments to a Python function?
We can pass multiple arguments to a function. For example,
def print_name(first_name, last_name): print(first_name, last_name) print_name(“Amit”, “Sen”)
The program will print the following output:
Amit Sen
Similarly, we can pass multiple arguments of different data types to a function. For example,
def user_information(name, age, contact_number, is_married): print("Name: ", name) print("Age: ", age) print("Contact Number: ", contact_number) print("Is Married: ", is_married) user_information("Amit Sen", 23, "1234", False)
The above program will print the following output:
Name: Amit Sen Age: 23 Contact Number: 1234 Is Married: False
How can we specify default values to function arguments in Python?
Let’s say a function has three parameters. If we do not provide the third argument while calling the function, the function takes a default value for the third parameter.
def user_information(name, age, contact_number = "Not Given"): print("Name: ", name) print("Age: ", age) print("Contact Number: ", contact_number)
So, we can call the function as user_information(“Amit Sen”, 23, “1234”), in which case the contact_number parameter will contain the value “1234.” But, we can also call the function as user_information(“John Smith”, 27). Please note that the third argument is not given while calling the function. So, the function will take the default value “Not Given” for the third …






0 Comments