Section 14.3 Check Point Questions11 questions
14.3.1
How do you create an empty set?
14.3.2
Can a list, set, or tuple have elements of different types?
14.3.3
Which of the following sets are created correctly?
s = {1, 3, 4} s = {{1, 2}, {4, 5}} s = {[1, 2], [4, 5]} s = {(1, 2), (4, 5)}
14.3.4
What are the differences between a list and a set? How do you
create a set from a list? How do you create a list from a set? How
do you create a tuple from a set?
14.3.5
Show the output of the following code:
students = {"peter", "john"} print(students) students.add("john") print(students) students.add("peterson") print(students) students.remove("peter") print(students)
14.3.6
Will the following code have a runtime error?
students = {"peter", "john"} students.remove("johnson") print(students)
14.3.7
Show the output of the following code:
student1 = {"peter", "john", "tim"} student2 = {"peter", "johnson", "tim"} print(student1.issuperset({"john"})) print(student1.issubset(student2)) print({1, 2, 3} > {1, 2, 4}) print({1, 2, 3} < {1, 2, 4}) print({1, 2} < {1, 2, 4}) print({1, 2} <= {1, 2, 4})
14.3.8
Show the output of the following code:
numbers = {1, 4, 5, 6} print(len(numbers)) print(max(numbers)) print(min(numbers)) print(sum(numbers))
14.3.9
Show the output of the following code:
s1 = {1, 4, 5, 6} s2 = {1, 3, 6, 7} print(s1.union(s2)) print(s1 | s2) print(s1.intersection(s2)) print(s1 & s2) print(s1.difference(s2)) print(s1 - s2) print(s1.symmetric_difference(s2)) print(s1 ^ s2)
14.3.10
Show the output of the following code:
set1 = {2, 3, 7, 11} print(4 in set1) print(3 in set1) print(len(set1)) print(max(set1)) print(min(set1)) print(sum(set1)) print(set1.issubset({2, 3, 6, 7, 11})) print(set1.issuperset({2, 3, 7, 11}))
14.3.11
Show the output of the following code:
set1 = {1, 2, 3} set2 = {3, 4, 5} set3 = set1 | set2 print(set1, set2, set3) set3 = set1 - set2 print(set1, set2, set3) set3 = set1 & set2 print(set1, set2, set3) set3 = set1 ^ set2 print(set1, set2, set3)