In the vast world of programming, Python stands out for its simplicity and readability. One of its most powerful features is the dictionary data structure, allowing you to store multiple values in a single variable, denoted by curly braces. But what about storing three values? Let's delve into Python's dictionary with three values, exploring its creation, manipulation, and real-world applications.

Dictionaries in Python are essentially unordered collections of key-value pairs. Each key is unique and maps to a value. So, when we talk about a Python dict with three values, we're essentially referring to a dictionary with three key-value pairs. Let's get started!

Creating a Python dict with three values
Creating a Python dictionary with three values is as simple as defining the key-value pairs. The keys must be unique and can be a mix of data types, while the values can be of any data type, including other dictionaries or lists.

Here's a basic example:
my_dict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
print(my_dict)
This will output: {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

Using different data types as keys and values
As hinted earlier, the keys and values in a Python dictionary can be of different data types. Let's explore this with an example:
my_dict = {1: 'one', 2.5: 'two point five', (1, 2): 'a tuple'}
print(my_dict)
This will output: {1: 'one', 2.5: 'two point five', (1, 2): 'a tuple'}

Adding or modifying key-value pairs
Once a dictionary is created, you can add new key-value pairs or modify existing ones using the assignment operator (=).
my_dict = {'key1': 'value1', 'key2': 'value2'}
my_dict['key3'] = 'value3' # Adding a new key-value pair
my_dict['key1'] = 'new value 1' # Modifying an existing key-value pair
print(my_dict)
This will output: {'key1': 'new value 1', 'key2': 'value2', 'key3': 'value3'}

Accessing values in a Python dict with three values
To access a value in a dictionary, you use the key in square brackets. If the key does not exist, Python will return an error or None, depending on the setting of the option 'raise on missing'








Let's see this in action:
my_dict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
print(my_dict['key2']) # Output: value2
print(my_dict.get('key4')) # Output: None (safe access)
Looping through a Python dict with three values
To loop through a dictionary, you can use the items() method, which returns a list of tuples, where each tuple contains a key-value pair.
my_dict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
for key, value in my_dict.items():
print(f'{key}: {value}')
This will output: key1: value1 key2: value2 key3: value3
Python dictionaries with their unique key-value pairing provide a powerful and efficient way to store and manipulate data. With just three values, they can hold a wealth of information, making them an essential tool for any Python programmer. So, next time you need to store and manage data in your Python project, don't hesitate to reach for the dictionary.