Member-only story

Dictionaries in Python? | Straightforward Python

Developers Group
3 min readMay 1, 2021

In this article, you’ll learn everything about Python dictionaries; how they are created, accessing, adding, removing elements from them and various built-in methods.

Dictionaries are Python’s implementation of a data structure that is more generally known as an associative array. A dictionary consists of a collection of key-value pairs. Each key-value pair maps the key to its associated value.

You can define a dictionary by enclosing a comma-separated list of key-value pairs in curly braces ({}). A colon (:) separates each key from its associated value

thisdict = {
"brand": "Apple",
"model": "iPhone 12 pro",
"year": 2020
}

Creating Python Dictionary

Creating a dictionary is as simple as placing items inside curly braces {} separated by commas as stated above

An item has a key and a corresponding value that is expressed as a pair (key: value).

Create and print a dictionary:

thisdict = {
"brand": "Apple",
"model": "iPhone 12 pro",
"year": 2020
}
print(thisdict)

Accessing Elements from Dictionary

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Developers Group
Developers Group

Written by Developers Group

A Developer is responsible for coding, designing, deploying, and debugging development projects, typically on the server-side (or back-end).

No responses yet

Write a response