Syntax
Python Create a Dictionary Syntax
In Python, create a dictionary: creates key-value pairs — d = {"a": 1, "b": 2}
Quick Answer
- Syntax
d = {"a": 1, "b": 2}
PythonSyntax
Create a Dictionary
Code example
d = {"a": 1, "b": 2}
Creates key-value pairs.
How to create a dictionary in Python
- Open your Python file or editor.
- Copy the example, then replace its sample names and values for your code.
Python Create a Dictionary Syntax
Use d = {"a": 1, "b": 2}.
Related Syntax References
Frequently asked questions
What is the Python syntax for create a dictionary?
Use this pattern: d = {"a": 1, "b": 2}
Can I copy this Python code example?
Yes. Use Copy code and adapt the example to your program.
Is this Python syntax different on Mac or Windows?
No. The language syntax is the same across operating systems.
Official source · How we verify