Function Parameters

A function parameter is a named placeholder in a function's definition that receives a value when the function is called. Parameters let you write flexible functions that produce different results depending on the input they receive.

Defining Parameters

Parameters are listed inside the parentheses when a function is defined. When the function is called, the values passed in are called arguments, and they get assigned to the corresponding parameters.

def greet(name):
    print("Hello,", name)

greet("Abhay")

Here, name is the parameter, and "Abhay" is the argument passed when calling the function.

Default Parameter Values

You can assign a default value to a parameter, which is used automatically if no argument is provided for it during the function call.

def greet(name="Guest"):
    print("Hello,", name)

greet()          # Hello, Guest
greet("Priya")   # Hello, Priya
A function can have any number of parameters, but parameters with default values must always come after parameters without default values in the function definition.

Coming Up Next

Now that you understand how parameters work, the next section explores the different ways arguments can actually be passed into a function.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course