Python Data Types Flashcards

(7 cards)

1
Q

Which statement about tuples is true?
A. Tuples are mutable and support append()
B. Tuples are immutable and have no append() method
C. Tuples always contain only elements of the same type
D. Tuples support item assignment like list[0] = x

A

B — tuples are immutable and have no append().

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

When should you use a tuple?
A. When you need a mutable collection you will modify frequently
B. When you need a fixed, ordered collection or a hashable sequence (e.g., return multiple values, use as dict key)
C. When you need efficient numeric vector operations (like NumPy)
D. When you need to store key→value pairs

A

B — Use tuples for fixed/immutable ordered data and when hashability is required.

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

Which of these is a list literal containing the strings “a” and “b”?
A. (“a”, “b”)
B. [“a”, “b”]
C. {“a”: “b”}
D. set(“a”, “b”)

A

B

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

Which of these is a dict literal mapping the key ‘x’ to the value 1?
A. {‘x’: 1}
B. (‘x’, 1)
C. [‘x’ => 1]
D. {1, ‘x’}

A

A

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

When should you use a list?
A. When you need immutable, hashable sequences
B. When you need a mutable, ordered collection you will append/modify/sort frequently
C. When you need constant‑time key lookups by name
D. When you need an unordered set of unique items

A

B — Use lists for general-purpose, mutable ordered collections.

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

When should you use a dict?
A. When you need a mapping from unique keys to values with fast lookups/updates
B. When you need an ordered sequence of items accessed by index
C. When you need a mutable sequence that preserves duplicates and order only for iteration
D. When you need a fixed numeric array

A

A — Use dicts for keyed lookup/association and fast retrieval by key.

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

Which of these is a tuple literal containing the elements 1 and 2?
A. (1, 2)
B. [1, 2]
C. {1, 2}
D. “1,2”

A

A

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