Home / CSE MCQs / Python MCQs :: Python Tuples and Sets

CSE MCQs :: Python MCQs

  1. Which of the following statements is used to create an empty set?
  2. A.
    { }
    B.
    set()
    C.
    [ ].
    D.
    ( )

  3. What is the output of the following piece of code when executed in the python shell?

    a={1,2,3}
     a.intersection_update({2,3,4,5})
     a
  4. A.
    {2,3}
    B.
    Error, duplicate item present in list
    C.
    Error, no method called intersection_update for set data type
    D.
    {1,4,5}

  5. Which of the following lines of code will result in an error?
  6. A.
    s={abs}
    B.
    s={4, 'abc', (1,2)}
    C.
    s={2, 2.2, 3, 'xyz'}
    D.
    s={san}

  7. What is the output of the code shown below?

    s=set([1, 2, 3])
    s.union([4, 5])
    s|([4, 5])
  8. A.

    {1, 2, 3, 4, 5}

    {1, 2, 3, 4, 5}

    B.

    Error

    {1, 2, 3, 4, 5}

    C.

    {1, 2, 3, 4, 5}

    Error

    D.

    Error

    Error


  9. What is the output of the line of code shown below, if s1= {1, 2, 3}?

    s1.issubset(s1)
  10. A.
    True
    B.
    Error
    C.
    No output
    D.
    False

  11. Suppose t = (1, 2, 4, 3), which of the following is incorrect?

  12. A.
    print(t[3])
    B.
    t[3] = 45
    C.
    print(max(t))
    D.
    print(len(t))

  13. What will be the output?

    d = {"john":40, "peter":45}
    d["john"]
  14. A.
    40
    B.
    45
    C.
    john"
    D.
    peter"

  15. What is the output of the following piece of code when executed in Python shell?

    a=("Check")*3
     a
  16. A.
    ('Check','Check','Check')
    B.
    * Operator not valid for tuples
    C.
    ('CheckCheckCheck')
    D.
    Syntax error

  17. Is the following piece of code valid?

    a=2,3,4,5
     a
  18. A.
    Yes, 2 is printed
    B.
    Yes, [2,3,4,5] is printed
    C.
    No, too many values to unpack
    D.
    Yes, (2,3,4,5) is printed

  19. What is the output of the following code?

    a,b=6,7
     a,b=b,a
     a,b
  20. A.
    (6,7)
    B.
    Invalid syntax
    C.
    (7,6)
    D.
    Nothing is printed