The split and join Methods • Split method turns single string into list of substrings • Join method turns a list of strings into a single string. • Notice that these methods are inverses of each other
The tuple Object • Tuples, like lists, are ordered sequences of items • Difference – tuples cannot be modified in place – Have no append, extend, or insert method • Items of tuple cannot be directly deleted, sorted, or altered
The tuple Object • All other list functions and methods apply – Items can be accessed by indices – Tuples can be sliced, concatenated, and repeated • Tuples written as comma-separated sequences enclosed in parentheses – Can also be written without the parentheses.
Nested Lists • Beside numbers or strings, items can be lists or tuples. • Consider a list of tuples named L L[0] is the first tuple L[0][0] is the first item in the first tuple • And L[-1] is the last tuple L[-1][-1] is the last item in the last tuple
Immutable and Mutable Objects • Another way to say this – Lists can be changed in place – Numbers, strings, and tuples cannot • Objects changed in place are mutable • Objects that cannot be changed in place are immutable
Indexing, Deleting, and Slicing Out of Bounds • Python does not allow out of bounds indexing for individual items in lists and tuples – But does allow it for slices • Given list1 = [1, 2, 3, 4, 5] – Then print(list1[7]) print(list1[-7]) del list1[7]
Indexing, Deleting, and Slicing Out of Bounds • If left index in slice too far negative – Slice will start at the beginning of the list • If right index is too large, – Slice will go to the end of the list.