Chapter 3 Exercise Set 1: Doctest Exercises¶
Strings, lists, and tuples doctest exercises¶
Download test_scaffolding.py
, a file
containing the test scaffolding you were introduced to in Chapter 2 Exercise Set 1: Introducing Doctest,
or copy it from here:
"""
Put your tests here:
>>>
"""
# Put your solutions here:
if __name__ == "__main__":
import doctest
doctest.testmod()
Copy it to a new file for each doctest exercise.
""" >>> type(thing1) <class 'list'> >>> type(thing2) <class 'tuple'> >>> type(thing3) <class 'str'> """
""" >>> thing[3] 7 >>> len(thing) 5 """
""" >>> seq[2:5] [13, 11, 9] """
""" >>> whatsthis[2] 42 >>> type(whatsthis[4]) <class 'list'> >>> whatsthis[6:8] [11, 'what is this?'] >>> len(whatsthis) 10 """
""" >>> thing[2] = 17 >>> thing[2] 17 """
""" >>> tricky[4] 'this' >>> tricky[8] 42 >>> type(tricky[7]) <class 'tuple'> >>> type(tricky[0]) <class 'list'> >>> len(tricky) 12 """
""" >>> a_list[3] 42 >>> a_list[6] 'Ni!' >>> len(a_list) 8 """
""" >>> b_list[1:] ['Stills', 'Nash'] >>> group = b_list + c_list >>> group[-1] 'Young' """
""" >>> 'war' in mystery_list False >>> 'peace' in mystery_list True >>> 'justice' in mystery_list True >>> 'oppression' in mystery_list False >>> 'equality' in mystery_list True """
More strings, lists and tuples doctest exercises¶
""" >>> type(thing) <class 'list'> >>> type(thing[3]) <class 'tuple'> >>> type(thing[0]) <class 'str'> >>> type(thing[2]) <class 'list'> >>> len(thing) 4 >>> 8 in thing True """
""" >>> another_thing[1] 'happiness' >>> len(another_thing) 5 >>> 42 in another_thing True >>> type(another_thing) == type([]) False """
""" >>> seq[2:5] [13, 11, 9] """