0
0
Pythonprogramming~5 mins

Multiple parameters in Python

Choose your learning style9 modes available
Introduction

Multiple parameters let you send more than one piece of information to a function at the same time.

When you want a function to add two numbers.
When you need to greet someone by their first and last name.
When calculating the area of a rectangle using its width and height.
When you want to combine two strings into one message.
When you want to compare two values inside a function.
Syntax
Python
def function_name(param1, param2, param3):
    # code using param1, param2, param3

Parameters are separated by commas inside the parentheses.

You can use as many parameters as you need, but keep it simple.

Examples
This function takes two parameters: name and age, and prints a greeting.
Python
def greet(name, age):
    print(f"Hello {name}, you are {age} years old.")
This function adds two numbers and returns the result.
Python
def add(x, y):
    return x + y
This function describes a pet using two parameters.
Python
def describe_pet(pet_name, animal_type):
    print(f"I have a {animal_type} named {pet_name}.")
Sample Program

This program defines a function that multiplies two numbers and prints the result.

Python
def multiply(a, b):
    return a * b

result = multiply(4, 5)
print(f"4 times 5 is {result}")
OutputSuccess
Important Notes

Always give parameters clear names so your code is easy to understand.

Parameters are like placeholders; when you call the function, you give them actual values called arguments.

Summary

Functions can have multiple parameters separated by commas.

Parameters let functions work with different pieces of information.

Use clear names to make your code easy to read and maintain.