
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How do you create nested dict in Python?
You can create a nested dictionary using a nested syntax, just like you would define a JSON object.
example
a = { 'foo': 45, 'bar': { 'baz': 100, 'tru': "Hello" } }
You can access the objects just like you would access a normal dict. You can also use chaining of [] operators to get the deeper levels without declaring additional variables.
example
a = { 'foo': 45, 'bar': { 'baz': 100, 'tru': "Hello" } } print(a['bar']['baz'])
Output
This will give the output −
100
- Related Articles
- How do nested functions work in Python?
- How to create nested Python dictionary?
- Create a Pandas Dataframe from a dict of equal length lists in Python
- How do you create a list in Java?
- How do you create an empty list in Java?
- In MongoDB how do you use $set to update a nested value/embedded document?
- How do you create a clickable Tkinter Label?
- How do you create a list with values in Java?
- How to put multi-line comments inside a Python dict()?
- How do you properly ignore Exceptions in Python?
- How do you make an array in Python?
- How do you implement persistent objects in Python?
- How do you create line segments between two points in Matplotlib?
- How do you create a list from a set in Java?
- Creating DataFrame from dict of narray-lists in Python

Advertisements