Skip to content

Day 8: Python Arguments & Parameters

Understanding Function Parameters and Arguments in Python

In Python, when calling a function, you can pass values to the function as arguments. These values are then received by the function as parameters. You can also specify default values for parameters in the function definition. If an argument is not provided when the function is called, the default value will be used. In this context, the value that is being passed into the function is the argument, while the parameter is the variable that receives this value.

Function Parameters and Arguments in Python

# Argument and Parameters
def greet(name):
    print("Hello, " + name)

greet("John")  

In the above example, "John" is the argument, and "name" is the parameter.

Specifying Default Values for Parameters in Python

You can specify default values for parameters in the function definition. This means that if an argument is not provided when the function is called, the default value will be used.

# Specify default values for parameters in the function
def greet(name="Guest"):
    print("Hello, " + name)

greet()  # Output: "Hello, Guest"
greet("John")  # Output: "Hello, John"

In the above example, if no argument is passed to the greet function, it uses the default value "Guest" for the name parameter.

Understanding the difference between parameters and arguments, and how to use them in Python functions, can help you write more efficient and readable code. Stay tuned for more Python-related content.

Learn More

Want to learn more about Python for Machine Learning? Check out the full course HERE.


Need help mastering Machine Learning?

Don't just follow along — join me! Get exclusive access to me, your instructor, who can help answer any of your questions. Additionally, get access to a private learning group where you can learn together and support each other on your AI journey.