Positional arguments #
A positional argument is a parameter that is passed to a function based on its position in the function call. When calling a function with positional arguments, the arguments must be passed in the same order as the parameters are defined in the function definition.
Here's an example:
def greet(name, message):
print(f"{message}, {name}!")
greet("John", "Hello") # Output: Hello, John!
In the above example, the greet() function has two positional parameters, name and message. When we call the function on the last line, we pass "John" as the first argument, which is assigned to the name parameter, and "Hello" as the second argument, which is assigned to the message parameter. The function then prints out the message Hello, John!.
Exercise #
- Call the function
greet()with positional arguments.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules