My Report

Python Sets Test – 1


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. What will be the output of the following Python code?

>>> s={5,6}
>>> s*3

2. If a={5,6,7,8}, which of the following statements is false?

3. Which of the following statements is used to create an empty set?

4. If a={5,6,7}, what happens when a.add(5) is executed?

5. Which of these about a set is not true?

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

a = [5,5,6,7,7,7]
b = set(a)
def test(lst):
    if lst in b:
        return 1
    else:
        return 0
for i in  filter(test, a):
    print(i,end=" ")

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

>>> a={5,6,7,8}
>>> b={7,5,6,8}
>>> a==b

8. Which of the following is not the correct syntax for creating a set?

9. Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])

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

nums = set([1,1,2,3,3,3,4,4])
print(len(nums))

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

>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b

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

>>> a={4,5,6}
>>> b={2,8,6}
>>> a+b

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

>>> a={5,4}
>>> b={1,2,4,5}
>>> a<b

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

>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b

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

>>> a={3,4,5}
>>> b={5,6,7}
>>> 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.