Home Artificial Intelligence Python Dictionaries Quiz – AICORR.COM

Python Dictionaries Quiz – AICORR.COM

8
0


Welcome to the Python Dictionaries Quiz!

Dictionaries in Python are highly effective knowledge buildings that retailer key-value pairs. They permit for quick lookups, versatile knowledge storage, and simple modifications. This quiz will check your understanding of the right way to create, manipulate, and entry dictionaries in Python.

Every query is designed to strengthen your information of dictionary strategies, operations, and finest practices. Let’s see how effectively you realize Python dictionaries!

Desk of Contents:

  • Python quizzes for inexperienced persons sequence

Dictionaries Quiz


Quiz Questions

1. How do you create an empty dictionary in Python?

a) dict = {}
b) dict = []
c) dict = ()
d) dict = ""

2. What is going to dict1 = {"identify": "Alice", "age": 25} return for dict1["name"]?

a) "Alice"
b) "age"
c) 25
d) Error

3. Which methodology is used to get all of the keys in a dictionary?

a) keys()
b) values()
c) gadgets()
d) get_keys()

4. What does the next code return?

my_dict = {"a": 1, "b": 2, "c": 3}
print(my_dict.get("d", 10))

a) None
b) 10
c) d
d) Error

5. How do you examine if a key exists in a dictionary?

a) "key" in dict
b) dict.has("key")
c) dict.comprises("key")
d) dict.exists("key")

6. What does dict1.gadgets() return?

a) A listing of dictionary values
b) A listing of dictionary keys
c) A listing of key-value pairs as tuples
d) A string of dictionary contents

7. How will you take away an merchandise from a dictionary utilizing a key?

a) dict.pop(key)
b) dict.take away(key)
c) dict.delete(key)
d) del dict.key

8. What occurs should you attempt to entry a non-existent key utilizing dict[key]?

a) It returns None
b) It raises a KeyError
c) It provides the important thing with a default worth
d) It creates a brand new dictionary

9. Which methodology removes all key-value pairs from a dictionary?

a) clear()
b) popitem()
c) take away()
d) del()

10. Can dictionary keys be mutable knowledge sorts (like lists)?

a) Sure
b) No

11. How do you merge two dictionaries in Python 3.9+?

a) dict1.replace(dict2)
b) dict3 = dict1 + dict2
c) dict3 = dict1 | dict2
d) dict1.append(dict2)

12. What does dict1.values() return?

a) Record of dictionary values
b) Record of dictionary keys
c) Record of key-value pairs
d) Error

13. What is going to dict1.popitem() do?

a) Take away a random key-value pair
b) Take away the final inserted key-value pair
c) Take away the primary inserted key-value pair
d) Elevate an error

14. What’s the output of this code?

my_dict = {1: "a", 2: "b", 3: "c"}
print(my_dict[1])

a) "a"
b) 1
c) None
d) Error

15. What occurs if we attempt to assign an inventory as a dictionary key?

a) The important thing-value pair is added efficiently
b) Python raises a TypeError
c) The listing is routinely transformed to a tuple
d) The listing key’s ignored

16. How do you copy a dictionary with out modifying the unique?

a) dict2 = dict1.copy()
b) dict2 = dict1
c) dict2 = dict(dict1)
d) Each a and c

17. What’s the appropriate option to iterate over dictionary keys?

a) for key in dict.keys():
b) for key in dict:
c) for key, worth in dict.gadgets():
d) Each a and b

18. Can dictionary values be duplicated?

a) Sure
b) No

19. What is going to my_dict.setdefault("key", "worth") do if "key" doesn’t exist?

a) Add "key": "worth" to the dictionary
b) Elevate an error
c) Take away the present key
d) Return "key" with out modifying the dictionary

20. What would be the output of the next code?

d = {"x": 10, "y": 20}
d["z"] = d["x"] + d["y"]
print(d)

a) {"x": 10, "y": 20, "z": 30}
b) {"x": 10, "y": 20, "z": 10}
c) {"x": 10, "y": 20}
d) Error


How did you do? 🎯

  • 18-20 appropriate → 🏆 Glorious! You’re a Python features professional!
  • 14-17 appropriate → 👍 Nice job! Hold practising.
  • 10-13 appropriate → 🙂 Good, however there’s room for enchancment.
  • Under 10 → 🤔 No worries! Evaluation the ideas and check out once more.

by AICorr Workforce

We’re proud to supply our intensive information to you, at no cost. The AICorr Workforce places loads of effort in researching, testing, and writing the content material throughout the platform (aicorr.com). We hope that you simply be taught and progress ahead.

Previous articleA International Recognition of Indi
Next articleAI updates from the previous week: New OpenAI fashions, NVIDIA AI-Q Blueprint, and Anthropic’s Google Workspace integration — April 18, 2025

LEAVE A REPLY

Please enter your comment!
Please enter your name here