• JUPYTER
  • FAQ
  • View as Code
  • Python 3 Kernel
  • View on GitHub
  • Execute on Binder
  • Download Notebook
  1. learn-python3
  2. notebooks
  3. beginner
  4. exercises

1. Fill missing pieces¶

Fill ____ pieces below to have correct values for lower_cased, stripped and stripped_lower_case variables.

In [ ]:
original = " Python strings are COOL! "
lower_cased = original._____
stripped = ____.strip()
stripped_lower_cased = original._____._____

Let's verify that the implementation is correct by running the cell below. assert will raise AssertionError if the statement is not true.

In [ ]:
assert lower_cased == " python strings are cool! "
assert stripped == "Python strings are COOL!"
assert stripped_lower_cased == "python strings are cool!"

2. Prettify ugly string¶

Use str methods to convert ugly to wanted pretty.

In [ ]:
ugly = " tiTle of MY new Book\n\n"
In [ ]:
# Your implementation:
pretty = "TODO"

Let's make sure that it does what we want. assert raises AssertionError if the statement is not True.

In [ ]:
print(f"pretty: {pretty}")
assert pretty == "Title Of My New Book"

3. Format string based on existing variables¶

Create sentence by using verb, language, and punctuation and any other strings you may need.

In [ ]:
verb = "is"
language = "Python"
punctuation = "!"
In [ ]:
# Your implementation:
sentence = "TODO"
In [ ]:
print(f"sentence: {sentence}")
assert sentence == "Learning Python is fun!"

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by OVHcloud

nbviewer GitHub repository.

nbviewer version: 8b013f7

nbconvert version: 7.2.3

Rendered (Tue, 10 Jun 2025 07:09:26 UTC)