INF1511-MCQ-PACK.
,INF1511-MCQ-PACK.
1. Which of the following are true for objects of Python’s set type:
The order of elements in a set is significant.
A given element can’t appear in a set more than once.
A set may contain elements that are mutable.
Sets are mutable.
2. Which of the following define the set {'a', 'b', 'c'}:
s = {('a', 'b', 'c')}
s = set('a', 'b', 'c')
3. What Python expression tests whether the string 'foo' is a
member of set s?
'foo' in s
4. You have a set s defined as follows:
s = {100, 200, 300}
Which one of the following statements does not correctly
produce the union of s and the set {300, 400, 500}:
s | [300, 400, 500]
s | {300, 400, 500}
s.union({300, 400, 500})
s | set([300, 400, 500])
s.union([300, 400, 500])
s.union(set([300, 400, 500]))
, INF1511-MCQ-PACK.
5. What is the result of this statement:
{'b', 'r', 'a'}
{'q', 'r', 'x', 'u', 'b', 'a'}
{}
set()
6. What is the result of this statement:
{1, 2, 6, 7}
set()
{1, 2}
{3, 4, 5, 6, 7}
7. Consider the following expression involving two sets x and y:
This expression is True for any sets x and y—true or false?
False
True
8. What is the result of the highlighted expression:
It raises an exception.
set()
True
False
,INF1511-MCQ-PACK.
1. Which of the following are true for objects of Python’s set type:
The order of elements in a set is significant.
A given element can’t appear in a set more than once.
A set may contain elements that are mutable.
Sets are mutable.
2. Which of the following define the set {'a', 'b', 'c'}:
s = {('a', 'b', 'c')}
s = set('a', 'b', 'c')
3. What Python expression tests whether the string 'foo' is a
member of set s?
'foo' in s
4. You have a set s defined as follows:
s = {100, 200, 300}
Which one of the following statements does not correctly
produce the union of s and the set {300, 400, 500}:
s | [300, 400, 500]
s | {300, 400, 500}
s.union({300, 400, 500})
s | set([300, 400, 500])
s.union([300, 400, 500])
s.union(set([300, 400, 500]))
, INF1511-MCQ-PACK.
5. What is the result of this statement:
{'b', 'r', 'a'}
{'q', 'r', 'x', 'u', 'b', 'a'}
{}
set()
6. What is the result of this statement:
{1, 2, 6, 7}
set()
{1, 2}
{3, 4, 5, 6, 7}
7. Consider the following expression involving two sets x and y:
This expression is True for any sets x and y—true or false?
False
True
8. What is the result of the highlighted expression:
It raises an exception.
set()
True
False