w2 Flashcards
(57 cards)
what does \n mean
represents a new line
print(item1 * 5)
prints the item1 5 times
how do I combine strings
items = item1 + “\n” + item 2
words1 = item1.split()
separates the words on the string item1
words1 = item1.split(“a”)
split the string at every occurrence of a, removing a
is “item 1 = playstation” valid??
no nigga no spaces in variable names
What are lists
used for keeping track of a sequence of items
what does len() do
determines how many items (elements) are in a list
how to determine a specific item in list
my_comp[2]
how to determine last item in a list
my_comp[-1]
adding item to a list
listname.append(‘item_name’)
adding item to specific point/number
listname.append(specific index, ‘item_name’)
removing items
listname.remove(‘item_name’)
removing item to specific point/number
listname.pop(‘specific index’)
what happens if no index is given for removing items
will remove last item
explain negative indexing
refers from starting from the end, -1 refers to last item, -2 refers to second last item etc
what is index of first item
0
slicing code
list name[startindex:endindex]
detail about end index
it is always excluded
what happens when you leave out the start index from slicing i.e [:2]
will start from the first item
what happens when you leave out the end index from slicing i.e [2:]
will finish at the last item
changing a range of items?
list_name[start:end] = “values to update”
What is a tuple
An ordered sequence of elements that is unchangeable (immutable)
what is a set
A disorganised collection of unique elements