Python Practice Test MCQ Certified Go from 0 to Expert hero Set 16

What will be the output of the following Python code snippet?


Options are :

  • True
  • False
  • None
  • Error

Answer :Error

What will be the output of the following Python code snippet?


Options are :

  • 40
  • 45
  • "john"
  • "peter"

Answer :40

Python Certification Exam Preparation Set 1

Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use?


Options are :

  • d.delete("john":40)
  • d.delete("john")
  • del d["john"]
  • del d("john":40)

Answer :del d["john"]

Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?


Options are :

  • d.size()
  • len(d)
  • size(d)
  • d.len()

Answer :len(d)

What will be the output of the following Python code snippet?


Options are :

  • ["john", "peter"]
  • ["john":40, "peter":45]
  • ("john", "peter")
  • ("john":40, "peter":45)

Answer :["john", "peter"]

Python Certification Exam Preparation Set 62

Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]?


Options are :

  • Since "susan" is not a value in the set, Python raises a KeyError exception
  • It is executed fine and no exception is raised, and it returns None
  • Since "susan" is not a key in the set, Python raises a KeyError exception
  • Since "susan" is not a key in the set, Python raises a syntax error

Answer :Since "susan" is not a key in the set, Python raises a KeyError exception

Which of these about a dictionary is false?


Options are :

  • The values of a dictionary can be accessed using keys
  • The keys of a dictionary can be accessed using values
  • Dictionaries aren't ordered
  • Dictionaries are mutable

Answer :The keys of a dictionary can be accessed using values

Which of the following is not a declaration of the dictionary?


Options are :

  • {1: 'A', 2: 'B'}
  • dict([[1,"A"],[2,"B"]])
  • {1,"A",2"B"}
  • { }

Answer :{1,"A",2"B"}

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 3

What will be the output of the following Python code snippet?


Options are :

  • 1 A 2 B 3 C
  • 1 2 3
  • A B C
  • 1:"A" 2:"B" 3:"C"

Answer :1 A 2 B 3 C

What will be the output of the following Python code snippet?


Options are :

  • 1
  • A
  • 4
  • Invalid syntax for get method

Answer :A

What will be the output of the following Python code snippet?


Options are :

  • Error, invalid syntax
  • A
  • 5
  • 4

Answer :4

Python Certification Exam Preparation Set 65

What will be the output of the following Python code snippet?


Options are :

  • {1: 'A', 2: 'B', 3: 'C'}
  • C
  • {1: 3, 2: 3, 3: 3}
  • No method called setdefault() exists for dictionary

Answer :C

What will be the output of the following Python code snippet?


Options are :

  • {1: 'A', 2: 'B', 3: 'C', 4: 'D'}
  • None
  • Error
  • [1,3,6,10]

Answer :{1: 'A', 2: 'B', 3: 'C', 4: 'D'}

What will be the output of the following Python code?


Options are :

  • {1: 'A', 2: 'B', 3: 'C'}
  • Method update() doesn't exist for dictionaries
  • {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
  • {4: 'D', 5: 'E'}

Answer :{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}

Python Certification Exam Preparation Set 55

What will be the output of the following Python code?


Options are :

  • Error, copy() method doesn't exist for dictionaries
  • {1: 'A', 2: 'B', 3: 'C'}
  • {1: 'A', 2: 'D', 3: 'C'}
  • "None" is printed

Answer :{1: 'A', 2: 'B', 3: 'C'}

What will be the output of the following Python code?


Options are :

  • None
  • { None:None, None:None, None:None}
  • {1:None, 2:None, 3:None}
  • { }

Answer :{ }

Which of the following isn't true about dictionary keys?


Options are :

  • More than one key isn't allowed
  • Keys must be immutable
  • Keys must be integers
  • When duplicate keys encountered, the last assignment wins

Answer :Keys must be integers

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 29

What will be the output of the following Python code?


Options are :

  • {1: 5}
  • {1: 5, 2: 3}
  • Error, syntax error for pop() method
  • {1: 5, 3: 4}

Answer :{1: 5, 2: 3}

What will be the output of the following Python code?


Options are :

  • 9
  • 3
  • Too many arguments for pop() method
  • 4

Answer :9

What will be the output of the following Python code?


Options are :

  • 1 2 3
  • 'A' 'B' 'C'
  • 1 'A' 2 'B' 3 'C'
  • Error, it should be: for i in a.items():

Answer :1 2 3

Python Certification Exam Preparation Set 17

What will be the output of the following Python code?


Options are :

  • Syntax error
  • dict_items([('A'), ('B'), ('C')])
  • dict_items([(1,2,3)])
  • dict_items([(1, 'A'), (2, 'B'), (3, 'C')])

Answer :dict_items([(1, 'A'), (2, 'B'), (3, 'C')])

Which of the statements about dictionary values if false?


Options are :

  • More than one key can have the same value
  • The values of the dictionary can be accessed as dict[key]
  • Values of a dictionary must be unique
  • Values of a dictionary can be a mixture of letters and numbers

Answer :Values of a dictionary must be unique

What will be the output of the following Python code snippet?


Options are :

  • method del doesn't exist for the dictionary
  • del deletes the values in the dictionary
  • del deletes the entire dictionary
  • del deletes the keys in the dictionary

Answer :del deletes the entire dictionary

Python Practice Test MCQ Certified Go from 0 to Expert hero Set 7

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


Options are :

  • Removes an arbitrary element
  • Removes all the key-value pairs
  • Removes the key-value pair for the key given as an argument
  • Invalid method for dictionary

Answer :Removes an arbitrary element

What will be the output of the following Python code snippet?


Options are :

  • 3
  • 1
  • 2
  • 0

Answer :2

What will be the output of the following Python code snippet?


Options are :

  • 1
  • 2
  • 4
  • Error, the keys can't be a mixture of letters and numbers

Answer :4

Python Certification Exam Preparation Set 56

What will be the output of the following Python code snippet?


Options are :

  • Error, dictionary in a dictionary can't exist
  • 'Numbers': {1: 56, 3: 7}
  • {'Numbers': {1: 56}, 'Letters': {4: 'B'}}
  • {'Numbers': {1: 56, 3: 7}, 'Letters': {4: 'B'}}

Answer :{'Numbers': {1: 56, 3: 7}, 'Letters': {4: 'B'}}

What will be the output of the following Python code snippet?


Options are :

  • 0
  • None
  • 3
  • An exception is thrown

Answer :0

What will be the output of the following Python code snippet?


Options are :

  • 0
  • 2
  • Error as the key-value pair of 1:'A' is already deleted
  • 1

Answer :2

Python Certification Exam Preparation Set 13

What will be the output of the following Python code snippet?


Options are :

  • An exception is thrown
  • 3
  • 6
  • 2

Answer :6

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions