Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Positional Arguments | Positional and Optional Arguments
Python Functions Tutorial

bookPositional Arguments

In Python, positional arguments are function arguments passed to a function based on their position or order. When defining a function, you can specify the parameters it expects. When calling the function, you provide the corresponding arguments in the same order as the parameters.

def function_name(argument1, argument2):
    ...

In all the functions of the previous chapters, we used positional arguments by explicitly indicating the arguments in the () parentheses, and then calling the function with the arguments in the appropriate order.

We can also specify arguments using a dictionary with the argument name as a keyword and the argument value as a value:

def function_name(argument_name=default_value):
    ...

Using this type of specification allows us to specify arguments in any order.

123456789
# Function with two positional arguments def greet(name, age): print(f'Hello, {name}! You are {age} years old.') # Calling the `greet()` function using dictionary greet(age=25, name='Alex') # Calling the `greet()` function using ordered values greet('Alex', 25)
copy

This method of setting arguments is preferable because it enhances the readability and interpretability of the code.

question mark

Which statements are true about the function calls?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 4.35

bookPositional Arguments

Swipe to show menu

In Python, positional arguments are function arguments passed to a function based on their position or order. When defining a function, you can specify the parameters it expects. When calling the function, you provide the corresponding arguments in the same order as the parameters.

def function_name(argument1, argument2):
    ...

In all the functions of the previous chapters, we used positional arguments by explicitly indicating the arguments in the () parentheses, and then calling the function with the arguments in the appropriate order.

We can also specify arguments using a dictionary with the argument name as a keyword and the argument value as a value:

def function_name(argument_name=default_value):
    ...

Using this type of specification allows us to specify arguments in any order.

123456789
# Function with two positional arguments def greet(name, age): print(f'Hello, {name}! You are {age} years old.') # Calling the `greet()` function using dictionary greet(age=25, name='Alex') # Calling the `greet()` function using ordered values greet('Alex', 25)
copy

This method of setting arguments is preferable because it enhances the readability and interpretability of the code.

question mark

Which statements are true about the function calls?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1
some-alt