Beginners Python Cheat Sheet PCC Lists
Beginners Python Cheat Sheet PCC Lists
users = []
users.append('val')
users.append('bob')
users.append('mia')
Making a list
Changing an element
users[0] = 'valerie'
users[-2] = 'ronald'
To copy a list make a slice that starts at the first item and
ends at the last item. If you try to copy a list without using
this approach, whatever you do to the copied list will affect
the original list as well.
You can work with any set of elements from a list. A portion
of a list is called a slice. To slice a list start with the index of
the first item you want, then add a colon and the index after
the last item you want. Leave off the first index to start at
the beginning of the list, and leave off the last index to slice
through the end of the list.
middle_three = finishers[1:4]
Overwriting a tuple
dimensions = (800, 600)
print(dimensions)
dimensions = (1200, 900)
Defining a tuple
Looping through a tuple
Readability counts