PYTHON CORE · LESSON 42

Extra gaps

Method of strip · about 9 minutes

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

Gaps from the edges

Sometimes there are occasional gaps before or after a word. strip removes them at the edges.

word = "  кот  "
print(word.strip())

✦ The result is «кот» with no space around.

STEP 2

The middle remains.

strip does not remove the gap between two words: it is necessary to separate them.

name = "  Рыжий кот  "
print(name.strip())

✦ The gap between «Рыжий» and «кот» will remain.

IN-CLASS PRACTICE

Type the code yourself

Reprint and check where the gaps are inside the quote marks.

word = "  пёс  "
print(word.strip())
Open the editor for class work
HOMEWORK

Solve it yourself

Save « кот » with two spaces at the edges in word. Output text without spaces on the edges through strip.

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

Opening up your homework