Week 2 Flashcards
describe the way a list is indexed
the first item in a list in index 0 the second is index 1
what is the python operand for power
**
what is th eputhon operand to divide a number and reveal the reaminder
%
what is the python operand to divide a number and reveal the whole numbe rpart of the answer?
//
what are the two trypes of numbers
integers and floats
2 != 1+1 is?
False
‘aardvark’ > ‘zebra’
True
1 >= 2 or 9*8 == 72 is?
True
what is the purpose of the interactive shell
to try out code, nothing is saved when the shell is shut down.
How do you denote a comment, and what are they used for?
# make code easy for other users to read - helps when I GO BACK TO IT
what is the use of len
len finds the length of a List
how do i find the lenght of a list
len
myList.append
adds a new item to the list at the end
how do i add an item to a list at the end
myList.append
how do i change the item at index 1?
myList[1]= ‘dog’
myList[1] = ‘dog’
change sthe item at index 1
remove the item at index 0 and assign it to a variable
result = myList.pop(0)
result = myList.pop(0)
remove the item at index 0 and assign it to a variable
remove the last item of a list is done by
myList.pop()
myList.pop()
remove the last item
what do we pass a function? and what does it then do
an argument, it then does something and passes back a result.
what is a method
You can think of a method as something a particular kind of object knows how to do. For instance a list knows how to append a new item to itself. To apply the append method to a given list we use the dot notation:
how do i join to lists together?
[1, 2, 3, 5] + [8, 13, 21]
HOW DO I SLICE
aList[2:4]
slice from index 2 up to but not including index 4
aList[2:4]
slicing from index 2 up to but not including index 4
slice from index 3 till end?
aList[3:]
what is a string
in Python a string is simply a sequence of characters.
give an example of len being used on a string
myString = ‘algorithm’
len(myString)
9
what does immutable mean
means that once they are created that they cannot be changed, strings are immutable.
what does aString.split(‘a’) do?
splits the string stored in aString on the character ‘a’.