Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Combination of Positional and Optional Arguments | Arbitrary Arguments
course content

Course Content

Python Functions Tutorial

Combination of Positional and Optional ArgumentsCombination of Positional and Optional Arguments

Let's consider a function for calculating the total cost of smartphones with the ability to specify various attributes during initialization and function invocation.

Rules for Specifying Arguments


Positional Arguments

Positional arguments must be specified in the order they are defined in the function declaration. For example, in the function calculate_smartphone_cost, model and price are mandatory positional arguments.

Optional (Named) Arguments

Optional arguments can be specified either positionally or using named parameters. In the example, quantity and discount are optional arguments with default values that can be altered using named parameters during function invocation.

Default Values

If an optional argument is not specified during function call, its default value will be used. For instance, in the calculate_smartphone_cost function, if quantity and discount are not provided, they automatically take the values 1 and 0, respectively.

Named Parameters

Named parameters allow precise specification of values for optional arguments and determine their order of appearance. This enhances code clarity and readability, especially when dealing with multiple optional parameters.


This example and the rules for specifying arguments illustrate how to effectively use a combination of positional and named (optional) arguments to create functions that offer flexibility and ease of use, while maintaining code clarity and expected behavior.

1. What is the combination of positional and optional arguments in functions?
2. How do you define a function with positional arguments followed by optional arguments?

What is the combination of positional and optional arguments in functions?

Select the correct answer

How do you define a function with positional arguments followed by optional arguments?

Select the correct answer

Everything was clear?

Section 3. Chapter 3
course content

Course Content

Python Functions Tutorial

Combination of Positional and Optional ArgumentsCombination of Positional and Optional Arguments

Let's consider a function for calculating the total cost of smartphones with the ability to specify various attributes during initialization and function invocation.

Rules for Specifying Arguments


Positional Arguments

Positional arguments must be specified in the order they are defined in the function declaration. For example, in the function calculate_smartphone_cost, model and price are mandatory positional arguments.

Optional (Named) Arguments

Optional arguments can be specified either positionally or using named parameters. In the example, quantity and discount are optional arguments with default values that can be altered using named parameters during function invocation.

Default Values

If an optional argument is not specified during function call, its default value will be used. For instance, in the calculate_smartphone_cost function, if quantity and discount are not provided, they automatically take the values 1 and 0, respectively.

Named Parameters

Named parameters allow precise specification of values for optional arguments and determine their order of appearance. This enhances code clarity and readability, especially when dealing with multiple optional parameters.


This example and the rules for specifying arguments illustrate how to effectively use a combination of positional and named (optional) arguments to create functions that offer flexibility and ease of use, while maintaining code clarity and expected behavior.

1. What is the combination of positional and optional arguments in functions?
2. How do you define a function with positional arguments followed by optional arguments?

What is the combination of positional and optional arguments in functions?

Select the correct answer

How do you define a function with positional arguments followed by optional arguments?

Select the correct answer

Everything was clear?

Section 3. Chapter 3
some-alt