Python dict() Function (original) (raw)

Last Updated : 5 Jun, 2026

dict() function is a built-in constructor used to create dictionaries. A dictionary is a mutable collection of key-value pairs where each key is unique and insertion order is preserved.

Python `

d=dict(One = "1", Two = "2") print(d)

`

Output

{'One': '1', 'Two': '2'}

**Explanation: Here, we create a dictionary using keyword arguments. The keys One and Two are assigned the values "1" and "2" respectively.

Syntax

dict()
dict(mapping)
dict(iterable)
dict(**kwargs)
dict(mapping, **kwargs)

**Parameter:

**Return: The function returns a dictionary containing the specified key-value pairs.

**Note: mapping and iterable cannot be passed together as two positional arguments

**Examples

**Example 1: Creating shallow copy of the dictionary

Python `

d = {'a': 1, 'b': 2, 'c': 3}

shallow copy using dict

d_copy = dict(d)

reference copy

d_shallow = d

changing value in reference copy will change d

d_shallow['a'] = 10 print(d)

changing value in copied dictionary won't affect d

d_copy['b'] = 20 print(d)

`

Output

{'a': 10, 'b': 2, 'c': 3} {'a': 10, 'b': 2, 'c': 3}

**Explanation:

**Example 2: Creating dictionary using iterables

Python `

d = dict([('a', 1), ('b', 2), ('c', 3)], d=4) print(d)

`

Output

{'a': 1, 'b': 2, 'c': 3, 'd': 4}

**Explanation: