Hey there, for today’s tutorial, we will discuss how Python Print Dictionary, and we will learn it with the help of examples.
What is Python Dictionary?
Dictionaries are a data structure in the Python implementation that is more generally known as an associative array.
A Python dictionary consists of a collection of key-value pairs. Each key-value pair maps the key to its associated value.
Also read: How To Multiply In Python with Examples
Python Dictionary Methods
The table shown below shows the Python dictionary methods:
Python Dictionary Method | Description |
clear() | Removes all items from the dictionary. |
copy() | Returns a shallow copy of the dictionary. |
formkeys(seq[,v]) | Returns a new dictionary with the key from seq and value equal to v (defaults to None ) |
get(key[,d]) | Returns the value of the key . If the key does not exist, returns d (defaults to None ) |
items() | Return a new object of the dictionary items in (key, value) format. |
keys() | Returns a new object of the dictionary key. |
pop(key[,d]) | Removes the item with the key and returns its value, or d if the key is not found. If d is not provided and the key is not found, it raises KeyError . |
popitem() | Removes and returns an arbitrary item (key, value). If the dictionary is empty, it raises KeyError . |
setdefault(key[,d]) | Returns the corresponding value if the key is in the dictionary. If not, inserts the key with a value of d and returns d (defaults to None ). |
update([other]) | Updates the dictionary with the key/value pairs from other , overwriting existing keys. |
values() | Returns a new object of the dictionary’s values. |
Dictionary Built-in Functions in Python
The table shown below shows the Python dictionary’s built-in functions like all()
, any()
, len()
, cmp()
, sorted()
, etc., which are commonly used to perform different tasks.
Python Dictionary Built-in Function | Description |
all() | Return True if all keys of the dictionary are True (or if the dictionary is empty). |
any() | Return True if any key of the dictionary is true. If the dictionary is empty, return False . |
len() | Return the length (the number of items) in the dictionary. |
cmp() | Compares items of two dictionaries |
sorted() | Return a new sorted list of keys in the dictionary. |
Python Print Dictionary
Dictionaries are written with curly brackets and have keys and values:

To print dictionary items: key: value pairs, keys, or values, you can use an iterator for the corresponding key: value pairs, keys, or values, using dict.items(), dict.keys(), or dict.values() respectively and call print() function.
Example Program How To Print Dictionary In Python
Here’s an example of How To Print Dictionary In Python.
thisdict = {
"Name": "Angel Jude",
"Age": 26,
"Position": "Programmer"
}
print(thisdict)
When you execute the program, this will be the output:
{‘Name’: ‘Angel Jude’, ‘Age’: 26, ‘Position’: ‘Programmer’}
Python Dictionary Items
The Dictionary items are ordered, changeable, and do not allow duplicates.
Dictionary items are presented in key: value pairs and can be referred to by using the key name.
Example Program To print The Value of The Dictionary Item
Here’s an example of how to print the value of a dictionary item.
Print the “Position” value of the dictionary.
thisdict = {
"Name": "Angel Jude",
"Age": "26",
"Position": "Programmer"
}
print(thisdict["Position"])
When you execute the program, this will be the output:
Programmer
Ordered or Unordered?
When we say Dictionaries are ordered, it means the items have a defined order, and the order will not change.
Unordered means the items do not have a defined order; you cannot refer to an item by using an index.
Changeable
The Dictionaries are changeable, meaning we can change, add, or remove items after the dictionary has been created.
Duplicates Not Allowed
The Dictionaries cannot duplicate items with the same key:
Example Program
The duplicate values will overwrite existing values:
thisdict = {
"Name": "Angel Jude",
"Age": 26,
"Position": "Programmer",
"Position": "SEO Manager"
}
print(thisdict)
When you execute the program, this will be the output:
{‘Name’: ‘Angel Jude’, ‘Age’: 26, ‘Position’: ‘SEO Manager’}
Dictionary Lenght
To determine the number of items in a dictionary, use the len()
function:
Example
Print the number of items in a dictionary.
thisdict = {
"Name": "Angel Jude",
"Age": 26,
"Position": "Programmer"
}
print(len(thisdict))
When you execute the program, this will be the output:
3
Python Dictionary Items – Data Types
The values in dictionary items can be of any data type.
Example
string, int, boolean, and list data types:
thisdict = {
"Name": "Angel Jude",
"Age": 26,
"Single": False,
"Position": ["Programmer", "SEO Manager", "Writer"]
}
print(thisdict)
When you execute the program, this will be the output:
{‘Name’: ‘Angel Jude’, ‘Age’: 26, ‘Single’: False, ‘Position’: [‘Programmer’, ‘SEO Manager’, ‘Writer’]}
type()
From Python’s perspective, dictionaries are defined as objects with the data type ‘dict’ :
<class 'dict'>
Example
Print the data type of a dictionary:
thisdict = {
"Name": "Angel Jude",
"Age": 26,
"Single": False,
"Position": ["Programmer", "SEO Manager", "Writer"]
}
print(type(thisdict))
When you execute the program, this will be the output:
<class ‘dict’>
Summary
In this tutorial, we have completely discussed how to print a dictionary in Python in a different function, which we learn with the help of examples.
I hope this simple Python tutorial helped you a lot to comply with your requirements.
Inquiries
If you have any questions or suggestions about this simple tutorial, “How Python Print Dictionary with Examples,” please feel free to comment below.
Thank You!