PYTHON CORE · LESSON 38

The default argument

Convenient function · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

The function may have a backup option

The value after = inside the brackets of the function is used if nothing is transmitted when calling.

def greet(name="друг"):
    print("Привет, " + name)
greet()

✦ «Привет, друг» will appear.

STEP 2

You can transfer another meaning.

If you transfer the name in parentheses, you will not need a spare version.

def greet(name="друг"):
    print("Привет, " + name)
greet("Лев")

✦ Now «Привет, Лев» will appear.

IN-CLASS PRACTICE

Type the code yourself

Dial the function and call it without argument.

def wave(name="друг"):
    print("Привет, " + name)
wave()
Open the editor for class work
HOMEWORK

Solve it yourself

Create greet with the name default «друг» argument. The function outputs «Привет, » and name. Call greet without argument.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework