GoConqr has a new look! Let us know what you think.

Quiz

Sets in Python

PathaPadha Support 15 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (15)

  1. 1What is the output of the following ?

    sampleSet = {"Yellow", "Orange", "Black"}
    sampleSet.add("Blue")
    sampleSet.add("Orange")
    print(sampleSet)
    1. A{‘Blue’, ‘Orange’, ‘Yellow’, ‘Orange’, ‘Black’}
    2. B{‘Blue’, ‘Orange’, ‘Yellow’, ‘Black’}
  2. 2The union() method returns a new set with all items from both sets by removing duplicates
    1. ATrue
    2. BFalse
  3. 3Select all the correct ways to copy two sets
    1. Aset2 = set1.copy()
    2. Bset2 = set1
    3. Cset2 = set(set1)
    4. Dset2.update(set1)
  4. 4What is the output of the following

    sampleSet = {"Yellow", "Orange", "Black"}
    sampleSet.discard("Blue")
    print(sampleSet)
    1. A{‘Yellow’, ‘Orange’, ‘Black’}
    2. BKeyError: ‘Blue’
  5. 5The symmetric_difference() method returns a set that contains all items from both sets, but not the items that are present in both sets.
    1. ATrue
    2. BFalse
  6. 6What is the output of the following code

    aSet = {1, 'PYnative', ['abc', 'xyz'], True}
    print(aSet)
    1. A{1, ‘PYnative’, [‘abc’, ‘xyz’]}
    2. B{1, ‘PYnative’, [‘abc’, ‘xyz’], True}
    3. CTypeError
  7. 7Select which is true for Python set
    1. ASets are unordered.
    2. BSet doesn’t allow duplicate
    3. Csets are written with curly brackets {}
    4. Dset Allows duplicate
    5. Eset is immutable
    6. Fa set object does support indexing
  8. 8What is the output of the following set operation.

    set1 = {"Yellow", "Orange", "Black"}
    set2 = {"Orange", "Blue", "Pink"}

    set1.difference_update(set2)
    print(set1)
    1. A{‘Black’, ‘Yellow’}
    2. B{‘Yellow’, ‘Orange’, ‘Black’, ‘Blue’, ‘Pink’}
  9. 9What is the output of the following code

    sampleSet = {"Yellow", "Orange", "Black"}
    print(sampleSet[1])
    1. AYellow
    2. BSyntax Error
    3. COrange
  10. 10What is the output of the following union operation

    set1 = {10, 20, 30, 40}
    set2 = {50, 20, "10", 60}

    set3 = set1.union(set2)
    print(set3)
    1. A{40, 10, 50, 20, 60, 30}
    2. B{40, ’10’, 50, 20, 60, 30}
    3. C{40, 10, ’10’, 50, 20, 60, 30}
    4. DSynatxError: Different types cannot be used with sets

Information

Description
Coding Python Quiz on Sets in Python, created by PathaPadha Support on 27/10/2020.
Language
English
Views
704
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?