1. How do you create an empty dictionary in Python?
2. Given the dictionary student = {'name': 'Alex', 'age': 20}
, how do you access the value associated with the key 'name'
?
3. What happens if you try to access a key that does *not* exist in a dictionary using square brackets, like my_dict['unknown_key']
?
4. How can you add a new key-value pair ('city': 'London'
) to an existing dictionary called user_info
?
5. What is the primary purpose of a dictionary in Python?
6. Consider prefs = {'color': 'blue', 'size': 'M'}
. What happens if you execute prefs['color'] = 'red'
?
7. Which data type is commonly used for dictionary *keys*?
8. What are the components of a key-value pair in a dictionary?
9. Is the order of items guaranteed in dictionaries created in older Python versions (before 3.7)?
10. Can a dictionary store values of different data types (e.g., strings, numbers, lists) together?