{"id":38043,"date":"2021-06-30T19:37:52","date_gmt":"2021-06-30T14:07:52","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/"},"modified":"2025-06-09T21:18:34","modified_gmt":"2025-06-09T15:48:34","slug":"python-dictionary","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/","title":{"rendered":"Python Dictionary Tutorial with Examples"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-a-python-dictionary\">What is a Python Dictionary?<\/h2>\n\n\n\n<p>A Python dictionary is an unordered, mutable collection of items where each item is a key-value pair. You define a dictionary using curly braces, like <code>{'name': 'John', 'age': 30}<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-python-dictionaries-are-important\">Why Python Dictionaries are Important<\/h2>\n\n\n\n<p>Dictionaries are great for organizing data. They let you access information by a unique key, not by an index number. This makes your code clear and efficient. You use dictionaries to store user profiles, configuration settings, or any data with unique identifiers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-steps-to-use-python-dictionaries\">3 Steps to Use Python Dictionaries<\/h2>\n\n\n\n<p>Here\u2019s how you can start using dictionaries in Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-create-a-dictionary\">Step 1: Create a Dictionary<\/h3>\n\n\n\n<p>You create a dictionary by putting key-value pairs inside curly braces. Each key connects to a value. You separate keys from values with a colon (:). You separate each key-value pair with a comma (,).<\/p>\n\n\n\n<p>Here's how you create a simple dictionary:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Create a dictionary named &#039;user_profile&#039;\nuser_profile = {\n    &#039;name&#039;: &#039;Alice&#039;,\n    &#039;age&#039;: 25,\n    &#039;city&#039;: &#039;New York&#039;\n}\n\nprint(user_profile)\n# Output: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 25, &#039;city&#039;: &#039;New York&#039;}\n<\/pre><\/div>\n\n\n<p>You can also create an empty dictionary and add items later:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Create an empty dictionary\nempty_dict = {}\n\n# Add a key-value pair\nempty_dict&#x5B;&#039;fruit&#039;] = &#039;apple&#039;\nempty_dict&#x5B;&#039;color&#039;] = &#039;red&#039;\n\nprint(empty_dict)\n# Output: {&#039;fruit&#039;: &#039;apple&#039;, &#039;color&#039;: &#039;red&#039;}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-access-dictionary-values\">Step 2: Access Dictionary Values<\/h3>\n\n\n\n<p>You access values in a dictionary using their keys. You put the key inside square brackets after the dictionary's name.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Access values from &#039;user_profile&#039;\nname = user_profile&#x5B;&#039;name&#039;]\nage = user_profile&#x5B;&#039;age&#039;]\n\nprint(f&quot;Name: {name}, Age: {age}&quot;)\n# Output: Name: Alice, Age: 25\n<\/pre><\/div>\n\n\n<p>If a key does not exist, Python will show a <code>KeyError<\/code>. You can use the <code>get()<\/code> method to avoid this. The <code>get()<\/code> method returns <code>None<\/code> or a default value if the key is not found.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Using get() to access values\ncountry = user_profile.get(&#039;country&#039;)\nprint(f&quot;Country: {country}&quot;)\n# Output: Country: None\n\n# Using get() with a default value\noccupation = user_profile.get(&#039;occupation&#039;, &#039;Unemployed&#039;)\nprint(f&quot;Occupation: {occupation}&quot;)\n# Output: Occupation: Unemployed\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-modify-and-delete-dictionary-items\">Step 3: Modify and Delete Dictionary Items<\/h3>\n\n\n\n<p>Dictionaries are mutable. This means you can change, add, or remove key-value pairs after you create them.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"add-or-update-items\">Add or Update Items<\/h4>\n\n\n\n<p>To add a new item, assign a value to a new key. If the key already exists, this will update its value.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Add a new item to &#039;user_profile&#039;\nuser_profile&#x5B;&#039;email&#039;] = &#039;alice@example.com&#039;\nprint(user_profile)\n# Output: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 25, &#039;city&#039;: &#039;New York&#039;, &#039;email&#039;: &#039;alice@example.com&#039;}\n\n# Update an existing item\nuser_profile&#x5B;&#039;age&#039;] = 26\nprint(user_profile)\n# Output: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 26, &#039;city&#039;: &#039;New York&#039;, &#039;email&#039;: &#039;alice@example.com&#039;}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"delete-items\">Delete Items<\/h4>\n\n\n\n<p>You use the <code>del<\/code> keyword to remove a key-value pair. You can also use <code>pop()<\/code> to remove an item and get its value back. The <code>clear()<\/code> method empties the dictionary.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Delete an item using del\ndel user_profile&#x5B;&#039;city&#039;]\nprint(user_profile)\n# Output: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 26, &#039;email&#039;: &#039;alice@example.com&#039;}\n\n# Remove an item and get its value using pop()\nremoved_email = user_profile.pop(&#039;email&#039;)\nprint(f&quot;Removed Email: {removed_email}&quot;)\nprint(user_profile)\n# Output: Removed Email: alice@example.com\n# Output: {&#039;name&#039;: &#039;Alice&#039;, &#039;age&#039;: 26}\n\n# Clear all items from the dictionary\nuser_profile.clear()\nprint(user_profile)\n# Output: {}\n<\/pre><\/div>\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dictionary-methods-you-can-use\">Dictionary Methods You Can Use<\/h2>\n\n\n\n<p>Python dictionaries have many built-in methods. These methods help you work with dictionary items.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>keys()<\/strong>: This method returns a view of all keys in the dictionary.<\/li>\n\n\n\n<li><strong>values()<\/strong>: This method returns a view of all values in the dictionary.<\/li>\n\n\n\n<li><strong>items()<\/strong>: This method returns a view of all key-value pairs (as tuples) in the dictionary.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmy_dict = {\n    &#039;product&#039;: &#039;laptop&#039;,\n    &#039;price&#039;: 1200,\n    &#039;quantity&#039;: 10\n}\n\n# Get all keys\nkeys = my_dict.keys()\nprint(f&quot;Keys: {list(keys)}&quot;) # Output: Keys: &#x5B;&#039;product&#039;, &#039;price&#039;, &#039;quantity&#039;]\n\n# Get all values\nvalues = my_dict.values()\nprint(f&quot;Values: {list(values)}&quot;) # Output: Values: &#x5B;&#039;laptop&#039;, 1200, 10]\n\n# Get all items\nitems = my_dict.items()\nprint(f&quot;Items: {list(items)}&quot;) # Output: Items: &#x5B;(&#039;product&#039;, &#039;laptop&#039;), (&#039;price&#039;, 1200), (&#039;quantity&#039;, 10)]\n<\/pre><\/div>\n\n\n<p>You can use these methods to loop through a dictionary.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Loop through keys\nprint(&quot;Looping through keys:&quot;)\nfor key in my_dict.keys():\n    print(key)\n\n# Loop through values\nprint(&quot;\\nLooping through values:&quot;)\nfor value in my_dict.values():\n    print(value)\n\n# Loop through items\nprint(&quot;\\nLooping through items:&quot;)\nfor key, value in my_dict.items():\n    print(f&quot;{key}: {value}&quot;)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"check-for-key-existence\">Check for Key Existence<\/h2>\n\n\n\n<p>You can check if a key exists in a dictionary using the <b><code>in<\/code> operator<\/b>. This helps you avoid <code>KeyError<\/code> before trying to access a value.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nuser_data = {&#039;name&#039;: &#039;Bob&#039;, &#039;age&#039;: 40}\n\n# Check if &#039;name&#039; key exists\nif &#039;name&#039; in user_data:\n    print(&quot;Name exists.&quot;)\nelse:\n    print(&quot;Name does not exist.&quot;)\n# Output: Name exists.\n\n# Check if &#039;email&#039; key exists\nif &#039;email&#039; in user_data:\n    print(&quot;Email exists.&quot;)\nelse:\n    print(&quot;Email does not exist.&quot;)\n# Output: Email does not exist.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"copying-dictionaries\">Copying Dictionaries<\/h2>\n\n\n\n<p>When you copy a dictionary, you need to be careful. A simple assignment like <code>new_dict = old_dict<\/code> creates a <b>reference<\/b>, not a true copy. Changes to <code>new_dict<\/code> will also affect <code>old_dict<\/code>.<\/p>\n\n\n\n<p>To create a real copy, use the <b><code>copy()<\/code> method<\/b> or the <b><code>dict()<\/code> constructor<\/b>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"shallow-copy\">Shallow Copy<\/h3>\n\n\n\n<p>A <b>shallow copy<\/b> creates a new dictionary. It copies the references of the nested objects. If your dictionary contains lists or other dictionaries, changing those nested objects in the copy will affect the original.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\noriginal_dict = {&#039;a&#039;: 1, &#039;b&#039;: &#x5B;2, 3]}\nshallow_copy_dict = original_dict.copy()\n\nprint(f&quot;Original: {original_dict}&quot;)\nprint(f&quot;Shallow Copy: {shallow_copy_dict}&quot;)\n# Output:\n# Original: {&#039;a&#039;: 1, &#039;b&#039;: &#x5B;2, 3]}\n# Shallow Copy: {&#039;a&#039;: 1, &#039;b&#039;: &#x5B;2, 3]}\n\n# Modify the shallow copy\nshallow_copy_dict&#x5B;&#039;a&#039;] = 100\nshallow_copy_dict&#x5B;&#039;b&#039;].append(4) # This modifies the list in both dictionaries\n\nprint(f&quot;Original after change: {original_dict}&quot;)\nprint(f&quot;Shallow Copy after change: {shallow_copy_dict}&quot;)\n# Output:\n# Original after change: {&#039;a&#039;: 1, &#039;b&#039;: &#x5B;2, 3, 4]}\n# Shallow Copy after change: {&#039;a&#039;: 100, &#039;b&#039;: &#x5B;2, 3, 4]}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"deep-copy\">Deep Copy<\/h3>\n\n\n\n<p>A <b>deep copy<\/b> creates a completely independent copy, including all nested objects. Use the <b><code>deepcopy()<\/code> function<\/b> from the <b><code>copy<\/code> module<\/b> for this.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport copy\n\noriginal_dict_nested = {&#039;data&#039;: {&#039;value&#039;: 10}}\ndeep_copy_dict = copy.deepcopy(original_dict_nested)\n\nprint(f&quot;Original: {original_dict_nested}&quot;)\nprint(f&quot;Deep Copy: {deep_copy_dict}&quot;)\n# Output:\n# Original: {&#039;data&#039;: {&#039;value&#039;: 10}}\n# Deep Copy: {&#039;data&#039;: {&#039;value&#039;: 10}}\n\n# Modify the deep copy\ndeep_copy_dict&#x5B;&#039;data&#039;]&#x5B;&#039;value&#039;] = 20\n\nprint(f&quot;Original after change: {original_dict_nested}&quot;)\nprint(f&quot;Deep Copy after change: {deep_copy_dict}&quot;)\n# Output:\n# Original after change: {&#039;data&#039;: {&#039;value&#039;: 10}}\n# Deep Copy after change: {&#039;data&#039;: {&#039;value&#039;: 20}}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"dictionary-comprehension\">Dictionary Comprehension<\/h2>\n\n\n\n<p>You can create dictionaries using <b>dictionary comprehension<\/b>. This works like list comprehension but for dictionaries. It helps you build dictionaries from iterables, or filter and transform existing ones.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Create a dictionary from a list of numbers, squaring each number\nnumbers = &#x5B;1, 2, 3, 4, 5]\nsquared_dict = {num: num**2 for num in numbers}\nprint(f&quot;Squared Dictionary: {squared_dict}&quot;)\n# Output: Squared Dictionary: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n\n# Create a dictionary from two lists (keys and values)\nkeys = &#x5B;&#039;apple&#039;, &#039;banana&#039;, &#039;cherry&#039;]\nvalues = &#x5B;10, 20, 30]\nfruit_prices = {key: value for key, value in zip(keys, values)}\nprint(f&quot;Fruit Prices: {fruit_prices}&quot;)\n# Output: Fruit Prices: {&#039;apple&#039;: 10, &#039;banana&#039;: 20, &#039;cherry&#039;: 30}\n\n# Filter items from an existing dictionary\noriginal = {&#039;a&#039;: 1, &#039;b&#039;: 2, &#039;c&#039;: 3, &#039;d&#039;: 4}\neven_values = {key: value for key, value in original.items() if value % 2 == 0}\nprint(f&quot;Even Values Dictionary: {even_values}&quot;)\n# Output: Even Values Dictionary: {&#039;b&#039;: 2, &#039;d&#039;: 4}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"best-practices-for-python-dictionaries\">Best Practices for Python Dictionaries<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Choose Meaningful Keys<\/strong>: Use descriptive keys. This makes your code easier to read and understand.<\/li>\n\n\n\n<li><strong>Use get() for Safe Access<\/strong>: Use <code>get()<\/code> to prevent <code>KeyError<\/code> when you are not sure if a key exists.<\/li>\n\n\n\n<li><strong>Avoid Mutable Keys<\/strong>: Dictionary keys must be immutable (e.g., strings, numbers, tuples). You cannot use lists or other dictionaries as keys.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A Python dictionary stores data in key-value pairs. It helps you manage and retrieve information fast. This guide shows you how to master Python dictionaries in a few steps.<\/p>\n","protected":false},"author":41,"featured_media":38074,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[],"class_list":["post-38043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Dictionary Tutorial<\/title>\n<meta name=\"description\" content=\"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Dictionary Tutorial with Examples\" \/>\n<meta property=\"og:description\" content=\"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-30T14:07:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-09T15:48:34+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1365\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Python Dictionary Tutorial with Examples\",\"datePublished\":\"2021-06-30T14:07:52+00:00\",\"dateModified\":\"2025-06-09T15:48:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/\"},\"wordCount\":572,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1288009387.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/\",\"name\":\"Python Dictionary Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1288009387.jpg\",\"datePublished\":\"2021-06-30T14:07:52+00:00\",\"dateModified\":\"2025-06-09T15:48:34+00:00\",\"description\":\"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1288009387.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1288009387.jpg\",\"width\":1365,\"height\":768,\"caption\":\"python dictionary\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-dictionary\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Dictionary Tutorial with Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Dictionary Tutorial","description":"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/","og_locale":"en_US","og_type":"article","og_title":"Python Dictionary Tutorial with Examples","og_description":"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-06-30T14:07:52+00:00","article_modified_time":"2025-06-09T15:48:34+00:00","og_image":[{"width":1365,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Python Dictionary Tutorial with Examples","datePublished":"2021-06-30T14:07:52+00:00","dateModified":"2025-06-09T15:48:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/"},"wordCount":572,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/","name":"Python Dictionary Tutorial","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg","datePublished":"2021-06-30T14:07:52+00:00","dateModified":"2025-06-09T15:48:34+00:00","description":"Learn about Python dictionaries; how they are created, accessing, adding, removing elements from them, and various built-in methods.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg","width":1365,"height":768,"caption":"python dictionary"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-dictionary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Python Dictionary Tutorial with Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg",1365,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-768x432.jpg",768,432,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg",1365,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387.jpg",1365,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-640x768.jpg",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1288009387-150x84.jpg",150,84,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"A Python dictionary stores data in key-value pairs. It helps you manage and retrieve information fast. This guide shows you how to master Python dictionaries in a few steps.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/38043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=38043"}],"version-history":[{"count":25,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/38043\/revisions"}],"predecessor-version":[{"id":108810,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/38043\/revisions\/108810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/38074"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=38043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=38043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=38043"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=38043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}