4. Lists Flashcards
1
Q
How do you create a list of the first four prime numbers?
A
primes = [2, 3, 5, 7]
2
Q
Create a list of lists with products (A, B, C,…) on 3 shelves
A
products = [ [A, B, C] [D, E, F] G, H, I] ]
3
Q
Can a list contain multiple variable types?
A
Yes
4
Q
For list of planets, how would you change the first one to Manchester?
A
planets[0] = ‘Manchester’
5
Q
How would you change the last planet to London?
A
planets[-1] = 'London'
6
Q
How do you access the first 4 planets of the list?
A
planets[0:5]
7
Q
Can you modify lists? What word is used to describe this?
A
Yes, they are mutable
8
Q
A function attached to an object is called a ——-
A
method
9
Q
How do you add Birmingham to the end of the list of planets
A
planets.append(‘Birmingham’)
10
Q
How does a tuple differ from a list?
A
- Uses () rather than []
- It is immutable