Learn Pytho Flashcards
List: How to define one?
users[1, 2, “buckle”, “my”, ‘shoe’]
List: Difference between forwards, backwards indexing?
Forwards: positive index, start at 0
Backwards, negative index, starts at -1
Backwards counts arrays from the end.
List syntax: access n’th element?
users[n-1]
List syntax: append element?
users.append(‘item’)
Takes only one argument
PCC: Difference between variables and strings?
Variables store numbers, strings store text
1, 2
“high” “low”
PCC: What’s a tuple, how is it defined?
(1920, 1080)
Lists where the items can’t be modified.
Uses parentheses instead of square brackets.
() instead of []
List: Syntax of list insert?
users.insert(n-1, item)
Inserts item in n’th place, pushing the rest
List: Delete by position n
del users(n-1)
List: Delete by item
users.remove(item)
Clever. Scans list for item and removes the first item that matches.
List: “Pop” or take item n from list
Pop last?
users. pop(n-1)
users. pop()
List: find length?
len(users)
List: Sort in reverse alphabetical permanently?
users.sort(reverse = True)
List: Reverse order?
users.reverse()
List: print all items
for user in users:
print(user)
Remember the four spaces.
List: slice a list
users(ni:nf)
ni = index of first item
nf = index of last item
blank = take the first (or last) item)