Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

What is a set in Python?
A. A mutable sequence
B. An unordered collection of unique elements
C. A collection of key-value pairs
D. An ordered collection of unique elements
Direction: Choose the correct option

Q2.

How do you create an empty set?
A. ()
B. {}
C. []
D. set()
Direction: Choose the correct option

Q3.

What is the output of `{1,2,3} | {2,3,4}`?
A. {2,3}
B. {1,2,3,4}
C. {1,2,3,4}
D. {1,2,3,4}
Direction: Choose the correct option

Q4.

How do you add an element to a set `s`?
A. s.insert(5)
B. s.add(5)
C. s.append(5)
D. s.push(5)
Direction: Choose the correct option

Q5.

What does `s.remove(5)` do if 5 is not in the set?
A. Returns None
B. Ignores it
C. Raises KeyError
D. Adds 5
Direction: Choose the correct option

Q6.

What is the output of `{1,2,3} & {2,3,4}`?
A. {2,3}
B. {2,3,4}
C. {1,4}
D. {1,2,3,4}
Direction: Choose the correct option

Q7.

How do you test if a set is a subset of another?
A. s1.issubset(s2)
B. s1 <= s2
C. Both A and B
D. s1.subset(s2)
Direction: Choose the correct option

Q8.

Which of the following is a valid set?
A. {1,2,3,}
B. {1,2,3}
C. {1,2,3}
D. All of the above
Direction: Choose the correct option

Q9.

What does `s = set([1,2,2,3])` produce?
A. {1,2,3}
B. Error
C. {1,2,2,3}
D. [1,2,3]
Direction: Choose the correct option

Q10.

Can a set contain another set?
A. Only as a tuple
B. No, because sets are unhashable
C. Yes
D. Only as a frozenset