>>> sample_list[3] 'Eric' >>> print(sample_list) ['Graham', 'John', 'Terry', 'Eric', 'Terry', 'Michael'] >>> sample_string[8] = 'f' Traceback (most recent call last): File "", line 1, in sample_string[8] = 'f' TypeError: 'str' object does not support item assignment >>>
>>> name = "Old Woman" >>> person = name >>> name = "Dennis" >>> print(name) Dennis >>> print(person) Old Woman
>>> dish = ["Spam", "Spam", "Spam", "Spam", "Spam", "Spam", "baked beans", "Spam", "Spam", "Spam", "Spam"] >>> mr_buns_order = dish >>> print(dish) ['Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'baked beans', 'Spam', 'Spam', 'Spam', 'Spam'] >>> print(mr_buns_order) ['Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'baked beans', 'Spam', 'Spam', 'Spam', 'Spam'] >>> dish[6] = "Spam" >>> print(mr_buns_order) ['Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam'] >>> print(dish) ['Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam', 'Spam']
Working with Lists
len(some_list)
max(some_list)
>>> batch_sizes = [15, 6, 89, 34, 65, 35] >>> max(batch_sizes) 89 >>> python_vareties = ['Burmese Python', 'African Rock Python', 'Ball Python', 'Reticulated Python', 'Angolan Python'] >>> max(python_varieties) Traceback (most recent call last): File "", line 1, in max(python_varieties) NameError: name 'python_varieties' is not defined >>> max(python_vareties) 'Reticulated Python'
sorted
>>> sorted(batch_sizes) [6, 15, 34, 35, 65, 89] >>> sorted(batch_sizes, reverse=True) [89, 65, 35, 34, 15, 6] >>> print(batch_sizes) [15, 6, 89, 34, 65, 35]