No Result
View All Result
Sunday, September 24, 2023
  • Login
Getting Placed
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
No Result
View All Result
Getting Placed
No Result
View All Result

Python MCQs on SET: SET 4

Badal Yadav by Badal Yadav
April 28, 2021
in Python
0
python

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

s=set()

type(s)

a) <’set’>

b) <class ‘set’>

c) set

d) class set

Check Answer

Answer: b

32. The following Python code results in an error.

s={2, 3, 4, [5, 6]}

a) True

b) False

Check Answer

Answer: a
The set data type makes use of a principle known as hashing. This means that each item in the set should be hashable. Hashable in this context means immutable. List is mutable and hence the line of code shown above will result in an error.

33. Set makes use of __________

Dictionary makes use of ____________

a) keys, keys

b) key values, keys

c) keys, key values

d) key values, key values

Check Answer

Answer: c
Set makes use of keys.
Dictionary makes use of key values.

34. Which of the following lines of code will result in an error?

a) s={abs}

b) s={4, ‘abc’, (1,2)}

c) s={2, 2.2, 3, ‘xyz’}

d) s={san}

Check Answer

Answer: d
The line: s={san} will result in an error because ‘san’ is not defined. The line s={abs} does not result in an error because abs is a built-in function. The other sets shown do not result in an error because all the items are hashable.

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

s={2, 5, 6, 6, 7}

s

a) {2, 5, 7}

b) {2, 5, 6, 7}

c) {2, 5, 6, 6, 7}

d) Error

Check Answer

Answer: b
Duplicate values are not allowed in sets. Hence, the output of the code shown above will be a set containing the duplicate value only once. Therefore the output is: {2, 5, 6, 7}

36. Input order is preserved in sets.

a) True

b) False

Check Answer

Answer: b
The input order in sets is not maintained. This is demonstrated by the code shown below:
>>> s={2, 6, 8, 1, 5}
>>> s
{8, 1, 2, 5, 6}

37. Write a list comprehension for number and its cube for:

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

a) [x**3 for x in l]

b) [x^3 for x in l]

c) [x**3 in l]

d) [x^3 in l]

Check Answer

Answer: a
The list comprehension to print a list of cube of the numbers for the given list is: [x**3 for x in l].

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

s={1, 2, 3}

s.update(4)

s

a) {1, 2, 3, 4}

b) {1, 2, 4, 3}

c) {4, 1, 2, 3}

d) Error

Check Answer

Answer: d
The code shown above will result in an error because the argument given to the function update should necessarily be an iterable. Hence if we write this function as: s.update([4]), there will be no error.

39. Which of the following functions cannot be used on heterogeneous sets?

a) pop

b) remove

c) update

d) sum

Check Answer

Answer: d
The functions sum, min and max cannot be used on mixed type (heterogeneous) sets. The functions pop, remove, update etc can be used on homogenous as well as heterogeneous sets. An example of heterogeneous sets is: {‘abc’, 4, (1, 2)}

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

s={4>3, 0, 3-3}

all(s)

any(s)

a)

True
False

b)

False
True

c)

True
True

d)

False
False

Check Answer

Answer: b
The function all returns true only if all the conditions given are true. But in the example shown above, we have 0 as a value. Hence false is returned. Similarly, any returns true if any one condition is true. Since the condition 4>3 is true, true is returned.

Page  1  2  3  4  5  6

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling
Previous Post

Python MCQs on SET: SET 3

Next Post

Python MCQs on SET: SET 5

Badal Yadav

Badal Yadav

Next Post
python

Python MCQs on SET: SET 5

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us on Google News
No Result
View All Result

Recent Posts

  • Mustard Oil Price: सस्ता हुआ सरसों का तेल, खरीदने वालों की लगी भीड़
  • Bhojpuri Video: पवन सिंह ने रात के अंधेरे में मोनालिसा के बदन पर फेरा हाथ, मच गया बवाल
  • Gori Nagori ने उछल-उछल कर तोड़ दिया स्टेज, लगाए ताबड़तोड़ ठुमके
  • Haryanvi Dance: भरी जवानी में Gori Nagori के लगाए लटके-झटकें, देख बूढ़ों में आया जोश
  • Gori Nagori ने स्टेज पर उछल उछल कर लगाए जोरदार ठुमके, वायरल हुआ वीडियो

Recent Comments

  • Abhishek on Win 11 Download Links

Archives

  • September 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • August 2022
  • July 2022
  • October 2021
  • July 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • April 2020
  • February 2020

Categories

  • Admit Card
  • Algorithm and Programs
  • Exam
  • Internship
  • Java
  • Jobs
  • latest
  • politics and entertainment
  • Python
  • Result
  • Trademark
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • Privacy Policy
  • DMCA
  • Terms of Use
  • Sitemap

© 2020 Getting Placed

No Result
View All Result
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship

© 2020 Getting Placed

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In