My Report

Python Sets Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Is the following Python code valid?

>>> a=frozenset([5,6,7])
>>> a
>>> a.add(5)

2. What will be the output of the following Python code?

>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a

3. Is the following Python code valid?

a={1,2,3}
b={1,2,3,4}
c=a.issuperset(b)
print(c)

4. Set members must not be hashable.

5. What will be the output of the following Python code?

>>> a={5,6,7,8}
>>> b={7,8,9,10}
>>> len(a+b)

6. What is the syntax of the following Python code?

>>> a=frozenset(set([5,6,7]))
>>> a

7. What will be the output of the following Python code?

a={1,2,3}
b={1,2,3}
c=a.issubset(b)
print(c)

8. Which of these about a frozenset is not true?

9. What will be the output of the following Python code?

>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}

10. What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a.add(4)
>>> b

11. What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a
>>> b.remove(3)
>>> a

12. What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=a.copy()
>>> b.add(4)
>>> a

13. What will be the output of the following Python code?

>>> a={5,6,7}
>>> sum(a,5)

14. What will be the output of the following Python code?

>>> a={1,2,3}
>>> a.intersection_update({2,3,4,5})
>>> a

15. What will be the output of the following Python code?

>>> a={1,2,3}
>>> b=frozenset([3,4,5])
>>> a-b

 

Start practicing “1000 MCQs on Python”, and once you are ready, you can take tests on all topics by attempting our “Python Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.