Strings#
1. Fill missing pieces#
Fill ____
pieces below to have correct values for lower_cased
, stripped
and stripped_lower_case
variables.
original = ' Python strings are COOL! '
lower_cased = original._____
stripped = ____.strip()
stripped_lower_cased = original._____._____
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 2
1 original = ' Python strings are COOL! '
----> 2 lower_cased = original._____
3 stripped = ____.strip()
4 stripped_lower_cased = original._____._____
AttributeError: 'str' object has no attribute '_____'
Let’s verify that the implementation is correct by running the cell below. assert
will raise AssertionError
if the statement is not true.
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
.
ugly = ' tiTle of MY new Book\n\n'
# Your implementation:
pretty = 'TODO'
Let’s make sure that it does what we want. assert
raises AssertionError
if the statement is not True
.
print('pretty: {}'.format(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.
verb = 'is'
language = 'Python'
punctuation = '!'
# Your implementation:
sentence = 'TODO'
print('sentence: {}'.format(sentence))
assert sentence == 'Learning Python is fun!'