Multiple Choice Questions-tuples & Dictionaries

20 Questions | Attempts: 1248
Share

SettingsSettingsSettings
Multiple Choice Questions-tuples & Dictionaries - Quiz

.


Questions and Answers
  • 1. 
    To which of the following the “in” operator can be used to check if an item is in it?
    • A. 

      Lists

    • B. 

      Dictionary

    • C. 

      Tuples

    • D. 

      All of the above

  • 2. 
    Which of the following is a Python tuple?
    • A. 

      [1, 2, 3]

    • B. 

      (1,2,3)

    • C. 

      {1, 2, 3}

    • D. 

      {}

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

      Print(t[3])

    • B. 

      T[3] = 45

    • C. 

      Print(max(t))

    • D. 

      Print(len(t))

  • 4. 
    What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]
    • A. 

      (1, 2)

    • B. 

      (1, 2, 4)

    • C. 

      (2,4)

    • D. 

      (2, 4, 3)

  • 5. 
    What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1]
    • A. 

      (1, 2)

    • B. 

      (1, 2, 4)

    • C. 

      (2,4)

    • D. 

      (2, 4, 3)

  • 6. 
    What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]
    • A. 

      [2, 3, 9]

    • B. 

      [1, 2, 4, 3, 8, 9]

    • C. 

      [1, 4, 8]

    • D. 

      (1, 4, 8)

  • 7. 
    What will be the output of the following Python code? d = {"john":40, "peter":45} d["john"]
    • A. 

      40

    • B. 

      45

    • C. 

      “john”

    • D. 

      “peter”

  • 8. 
    What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t
    • A. 

      (1, 2, 1, 2)

    • B. 

      [1, 2, 1, 2]

    • C. 

      (1, 1, 2, 2)

    • D. 

      [1, 1, 2, 2]

  • 9. 
    What will be the output of the following Python code? >>>t1 = (1, 2, 4, 3) >>>t2 = (1, 2, 3, 4) >>>t1 < t2
    • A. 

      True

    • B. 

      False

    • C. 

      Error

    • D. 

      None

  • 10. 
    Which of the following statements create a dictionary?
    • A. 

      D = {}

    • B. 

      D = {“john”:40, “peter”:45}

    • C. 

      D = {40:”john”, 45:”peter”}

    • D. 

      All of the mentioned

  • 11. 
    What will be the output of the following Python code snippet? d = {"john":40, "peter":45}
    • A. 

      “john”, 40, 45, and “peter”

    • B. 

      “john” and “peter”

    • C. 

      40 and 45

    • D. 

      D = (40:”john”, 45:”peter”)

  • 12. 
    What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d
    • A. 

      True

    • B. 

      False

    • C. 

      None

    • D. 

      Error

  • 13. 
    Which of these about a dictionary is false?
    • A. 

      The values of a dictionary can be accessed using keys

    • B. 

      The keys of a dictionary can be accessed using values

    • C. 

      Dictionaries aren’t ordered

    • D. 

      Dictionaries are mutable

  • 14. 
    Which of the following is not a declaration of the dictionary?
    • A. 

      {1: ‘A’, 2: ‘B’}

    • B. 

      Dict([[1,”A”],[2,”B”]])

    • C. 

      {1,”A”,2”B”}

    • D. 

      { }

  • 15. 
    What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} for i,j in a.items():     print(i,j,end=" ")
    • A. 

      1 A 2 B 3 C

    • B. 

      1 2 3

    • C. 

      A B C

    • D. 

      1:”A” 2:”B” 3:”C”

  • 16. 
    What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(1,4))
    • A. 

      1

    • B. 

      A

    • C. 

      4

    • D. 

      Invalid syntax for get method

  • 17. 
    What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(5,4))
    • A. 

      Error, invalid syntax

    • B. 

      A

    • C. 

      5

    • D. 

      4

  • 18. 
    Which of the statements about dictionary values if false?
    • A. 

      More than one key can have the same value

    • B. 

      The values of the dictionary can be accessed as dict[key]

    • C. 

      Values of a dictionary must be unique

    • D. 

      Values of a dictionary can be a mixture of letters and numbers

  • 19. 
    What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a
    • A. 

      Method del doesn’t exist for the dictionary

    • B. 

      Del deletes the values in the dictionary

    • C. 

      Del deletes the entire dictionary

    • D. 

      Del deletes the keys in the dictionary

  • 20. 
    If a is a dictionary with some key-value pairs, what does a.popitem() do?
    • A. 

      Removes an arbitrary element

    • B. 

      Removes all the key-value pairs

    • C. 

      Removes the key-value pair for the key given as an argument

    • D. 

      Invalid method for dictionary

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.