🤔 Python Quiz: ⚗️ Dicts Alloy
Vladimir Ignatev
Posted on December 2, 2023
Follow me to learn 🐍 Python in 5-minute a day fun quizzes! Find previous quiz here.
Python 3.9 introduced new operators for dictionary merging. You'll learn more about making alloys from your dicts
by reading the original PEP-0584. PEP-0584 simplifies dictionary operations, enhancing Python's ease of use and readability..
Quiz
Which one of these code samples correctly demonstrates the use of Python's dictionary merging as guided by PEP 584?
Sample 1
dict1 = {'a': 1, 'b': 2}
dict2 = {'b': 3, 'c': 4}
merged_dict = dict1 | dict2
Sample 2
dict1 = {'a': 1, 'b': 2}
dict2 = {'b': 3, 'c': 4}
merged_dict = dict1 + dict2
Post your answer in the comments! 0 if you think that Sample 1 is correct, 1 otherwise. As usually, the correct answer will be explained in the first comment.
💖 💪 🙅 🚩
Vladimir Ignatev
Posted on December 2, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
python Mastering Python’s __name__ and __main__: Understanding Script Execution and Module Imports
November 1, 2024