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') s = {'a', 'b', 'c'} s = set('abc') 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} ({300, 400, 500}) s | set([300, 400, 500]) ([300, 400, 500]) (set([300, 400, 500])) INF1511-MCQ-PACK. 5. What is the result of this statement: {'b', 'a', 'r'} & set('qux') {'b', 'r', 'a'} {'q', 'r', 'x', 'u', 'b', 'a'} {} set() 6. What is the result of this statement: {1, 2, 3, 4, 5} - {3, 4} ^ {5, 6, 7} {1, 2, 6, 7} set() {1, 2} {3, 4, 5, 6, 7} 7. Consider the following expression involving two sets x and y: (x & y = x) and (x & y = 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: x = {1, 2, 3} y = {1, 2} persubset(x) It raises an exception. set() True False 9. Suppose a set s is defined as follows: s = {'foo', 'bar', 'baz', 'qux'} Which of the following remove element 'bar' from s: s -= {'bar'} s &= {'foo', 'baz', 'qux'} rd('bar') () del s['bar'] rence_update({'bar'}) 10. Which of the following are true about frozen sets: A frozen set can be a member of a set, and can serve as a dictionary key. If f is a frozen set, the statement f |= {'foo'} will raise an exception. You can define a frozen set with this syntax: f = f{'a', 'b', 'c'} If f is a frozen set, the statement ('foo') will raise an exception. 11. s = 'foo' t = 'bar' print('barf' in 2 * (s + t)) What is the output of the print() function call? True False
Written for
- Institution
- University of South Africa
- Course
- INF1511 - Visual Programming I
Document information
- Uploaded on
- November 25, 2021
- Number of pages
- 15
- Written in
- 2021/2022
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
inf1511
-
inf1511 mcq pack