Previous

Functions

3 / 6
Next

Default parameters let you assign a default value to a function argument. This means that if the caller does not provide a value for that parameter, the default will be used automatically. It helps make functions more flexible and easier to use.

For example:

def greet(name="friend"):
 print(f"Hello, {name}!")
greet() 
greet("Alice")

The first function call falls back to the default value "friend" and prints Hello, friend. The second function call overwrites the default parameter value and prints Hello, Alice.

Send

Default parameter values

Hint
Beginner

Write a function print_receipt_line with three parameters item, price, and amount. The function should print a line as it would appear on a receipt. The amount of items should default to 1.

For example, print_receipt_line ('pen', 1.45, 2) should print 2 x pen - 1.45.

Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!