---
title: "How to create dictionary in python?"  
description: "How to create dictionary in python?"  
author: "Amrita Bhattacharjee"  
published: 2023-03-28  
updated: 2023-04-20  
canonical: https://www.mindstick.com/forum/157623/how-to-create-dictionary-in-python  
category: "python"  
tags: ["python"]  
reading_time: 2 minutes  

---

# How to create dictionary in python?

How to create [dictionary](https://www.mindstick.com/articles/1500/hashtable-and-dictionary-in-c-sharp) in [python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python)?Give suitable example.

## Replies

### Reply by Aryan Kumar

In Python, you can create a dictionary by enclosing a comma-separated list of key-value pairs in curly braces **{}**. Each key-value pair consists of a key, followed by a colon **:**, and then the corresponding value.

Here's an example of creating a dictionary that maps names to ages:

```python
my_dict = {'Alice': 25, 'Bob': 30, 'Charlie': 35}
```

You can also create an empty dictionary and add key-value pairs to it later using square bracket notation **[]**:

```python
my_dict = {}
my_dict['Alice'] = 25
my_dict['Bob'] = 30
my_dict['Charlie'] = 35
```

You can also use the **dict()** constructor to create a dictionary from a list of tuples, where each tuple represents a key-value pair:

```python
my_list = [('Alice', 25), ('Bob', 30), ('Charlie', 35)]
my_dict = dict(my_list)
```

Once you have created a dictionary, you can access its values by using square bracket notation to specify the key:

```python
age = my_dict['Alice']
print(age)  # Output: 25
```

### Reply by Krishnapriya Rajeev

Dictionaries in Python are used to store data values in a key: value pair, unlike other data types that can hold only single values as an element. It is a collection that is ordered, and mutable and does not allow for duplicate values.

We can create a dictionary in Python as follows:

```plaintext
dict = {
"name": "John",
"age": 25,
"place": "London",
"job": "Engineer"
}
```

The values can be of any data type and can be duplicated, however, the keys cannot be duplicated and must be *immutable*. The keys are also *case-sensitive*.

We can add elements to a dictionary by using a new index key and assigning a value to it.

```plaintext
dict["nationality"] = "UK"
```

The update() method can be used to update the items within a dictionary. If the item does not exist, it will be added.

```plaintext
dict.update({"age": 28})
```


---

Original Source: https://www.mindstick.com/forum/157623/how-to-create-dictionary-in-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
