''' lists.py -- simple samples of a few list and tuple-related operations Jeff Ondich, 24 October 2006 Tianna Avery, November 2018, updated for Python 3 Read, predict the output, experiment. Note that there's a crash in the code as it stands. Why does it crash? Comment out the offending line once you understand why it's offensive. ''' print('=============== initializing and iterating through a simple list ==============') some_list = ['moose', 'emu', 'goat', 'squid'] for item in some_list: print(item) print() print('=============== "slicing" a list ==============') some_list = ['moose', 17, 'emu', 'goat', 'squid'] print('some_list --', some_list) print('some_list[2:3] --', some_list[2:3]) print('some_list[2:] --', some_list[2:]) print() # Note the difference between ['ant'] and 'ant' in this context some_list[2:4] = ['ant'] print('some_list --', some_list) some_list[2:4] = 'ant' print('some_list --', some_list) print() some_list.append('cow') some_list.extend(['kiwi']) print('some_list --', some_list) print() print('=============== tuples: read-only lists ==============') some_tuple = ('dog', 23, 'cat') for thing in some_tuple: print(thing) # This will crash. print('Try to add to a tuple...') some_tuple.append('gerbil') print() print('=============== more list operations ==============') # Go to https://docs.python.org/3/tutorial/datastructures.html # and play around with the various list operations.