Python Programming Quiz

Quiz on Sets in Python

Time left: 300 seconds

Q.1. Sets are immutable

Select Your Option

Items of a set in python are immutable (unchangeable)

Q.2. What is the possible output of followimg code?
          
            s = {1,2,3,5,1}
            print(s)
          
          

Select Your Option

Duplicate items are not allowed. If items appear multiple times, only one will be recognized in the set. Hence, in the given snippet, 1 will only be considered once.

Q.3. Order is retained in sets

Select Your Option

Items in a set are unordered.

Q.4. What is the possible output of followimg code?
          
            s = {'a','c','d','g'}
            s.add('b')
            print(s)

          
          

Select Your Option

The Python set add() method adds a given element to a set if the element is not present in the set in Python.

Q.5. What is the possible output of followimg code?
          
            s = {5,4,7,8,3,9}
            s.sort()
            print(s)
          
          

Select Your Option

A set is an unordered collection with no duplicate elements. sort() method is undefined for lists of sets.

Q.6. What will happen if an element is added to the below set:
          
            s = {1,2,3,4]
            s.add(4)
          
          

Select Your Option

Sets do not accept duplicate elements. Since the value 4 already exists inside the set, the set will remain unchanged.

Q.7. What is the possible output of followimg code?
          
            s1 = {10, 20, 30, 40}
            s2 = {50, 60, 70, 80}

            s3 = s1.union(s2)
            print(s3)
          
          

Select Your Option

The union() method returns a set that contains all items from the original set, and all items from the specified set(s).

Q.8. What is the possible output of followimg code?
          
            s = {'apple', 'orange', 'mango'}
            print(s[1])
          
          

Select Your Option

A set object is not subscriptable (i.e., we cannot access a particular index of the object).

Q.9. Duplicates are allowed in sets

Select Your Option

Duplicate items are not allowed. If items appear multiple times, only one will be recognized in the set.

Q.10. Which statement of the following is false regarding sets in Python?

Select Your Option

sets cannot be directly subtracted in Python.

Q.11. Initializing a set as " s = {"abc", 34, True, 40, "male"} " would give an error

Select Your Option

Sets can contain different types of data.

Q.12. What is the possible output of the follwing code?
          
            s1 = {'apple', 'orange', 'mango'}
            s2 = {'apple', 'orange', 'banana'}
            s3 = s1.union(s2)
            print(s3)
          
          

Select Your Option

The union() method returns a set that contains all items from the original set, and all items from the specified set(s). However, duplicate items are overlooked.

Q.13. What is the possible output of the follwing code?
          
            s1 = {"Yellow", "Orange", "Black"}
            s2 = {"Orange", "Blue", "Pink"}

            s3 = s2.difference(s1)
            print(s3)
          
          

Select Your Option

The difference() method returns a set that contains the difference between two sets (i.e, items that exist only in the first set, and not in both sets.)

Q.14. The symmetric_difference() method returns a set that contains all items from both sets, but not the items that are present in both sets.

Select Your Option

The Python Set symmetric_difference() Method is used to get the elements present in either of the two sets, but not common to both the sets.

Q.15. What is the possible output of the follwing code?
          
            s1 = {10, 20, 30, 40}
            s2 = {50, 60, 70, 80}

            s3 = s1.intersection(s2)
            print(s3)
          
          

Select Your Option

The intersection of two given set contains all the elements that are common to both sets.

Instructions:-

  1. This Quiz is based on Dictionary in Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post