Python Flashcards

(6 cards)

1
Q

What is the difference between a tuple and a list?

A

A list is an ordered, mutable collection of elements you can add, remove or change elements after the list is created. e.g. l = [1,2,3]

A tuple is an ordered but IMMUTABLE collection of elements. Once a tuple is created, its contents can’t be changed. e.g. t = (1,2,3) They are thus slightly more memory efficient. They are used for fixed data like coordinates or config values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is different about sets compared to tuples and lists?

A

Sets contain UNORDERED and only UNIQUE values e.g. {1,2,3}.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which brackets are used for sets, lists and tuples?

A

Sets = {}
lists = []
tuples = ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Out of sets, tuples and lists, which have only unique values? What is an implication of only having unique values?

A

Sets. They can’t be accessed with an index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Out of sets, tuples and lists, which have ordered values?

A

tuples and lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Out of sets, tuples and lists, which are mutable?

A

Sets and lists. Tuples are used for fixed values like coordinates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly