Learn with Yasir

Share Your Feedback

Python Dictionaries True/False Questions – Practice and Test Your Knowledge

Test your understanding of Python dictionaries with these true/false questions. Practice key concepts like key-value pairs, dictionary methods, and data manipulation to strengthen your Python programming skills. Ideal for beginners and students preparing for exams or interviews.

🔍 True or False

🟢 Beginner

  1. Dictionary keys must be immutable data types.
  2. Answer

    ✅ True – Dictionary keys must be hashable (immutable) types like strings, numbers, or tuples. This is because Python uses the key's hash value for quick lookups.


  3. Dictionaries maintain insertion order in all versions of Python.
  4. Answer

    ❌ False – Dictionaries only maintain insertion order in Python 3.7+. In earlier versions, dictionaries were unordered.


  5. The values in a dictionary can be of any data type.
  6. Answer

    ✅ True – While keys must be immutable, values can be any Python object - lists, dictionaries, functions, etc.


  7. You can nest dictionaries inside other dictionaries.
  8. Answer

    ✅ True – Dictionaries can contain other dictionaries as values, allowing for complex nested data structures.


🟡 Intermediate

  1. The get() method raises a KeyError if the key doesn't exist.
  2. Answer

    ❌ False – The get() method returns None (or a specified default) if the key doesn't exist, unlike direct access with square brackets which raises KeyError.


  3. You can use lists as dictionary keys.
  4. Answer

    ❌ False – Lists are mutable and cannot be used as dictionary keys. However, you can use tuples as keys since they're immutable.


  5. The update() method completely replaces the existing dictionary with the new one.
  6. Answer

    ❌ False – update() merges the new dictionary into the existing one, adding new keys and updating values for existing keys.


  7. The in operator checks for both keys and values in a dictionary.
  8. Answer

    ❌ False – The in operator only checks for keys in a dictionary. To check for values, you need to use the values() method (value in my_dict.values()).


🔴 Advanced

  1. Dictionary comprehensions can only be used with numeric keys.
  2. Answer

    ❌ False – Dictionary comprehensions can use any valid key-value pairs, not just numeric keys. For example: {str(x): x**2 for x in range(5)}


  3. The popitem() method removes a random item in Python versions before 3.7.
  4. Answer

    ✅ True – Before Python 3.7 (when dictionaries became ordered), popitem() would remove an arbitrary item. Now it removes the last inserted item.


📚 Related Resources

🧠 Practice & Progress

Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules