AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Python Dictionary


Python Tutorial » Python Dictionary

Python dictionary is an unordered collection of elements. Each element of a dictionary has a key-value pair.

Example: Dictionaries are written using curly brackets, and it have keys and values.
my_dictionar = {1: 'John', 2: 'Chris', 3: 'Tom', 4: 'Nick'}
print(my_dictionar)

Output:
{1: 'John', 2: 'Chris', 3: 'Tom', 4: 'Nick'}


Python Dictionaries NOT Allow Duplicates - examples



Example: Dictionaries cannot have two items with the same key
my_dictionar = {
1: 'John',
2: 'Chris',
3: 'Tom',
4: 'Nick',
4: 'Nicole' }
print(my_dictionar)
Output:
{1: 'John', 2: 'Chris', 3: 'Tom', 4: 'Nicole'}


How to Get the Length of a Dictionary


Example: how many elements this Dictionary has, using len() function
my_dictionar = {
1: 'John',
2: 'Chris',
3: 'Tom',
4: 'Nick',
4: 'Nicole' }

print(len(my_dictionar))
Output:
4


Dictionary Items - Data Types


The values in dictionary elements can be any data type:

Example: elements can be any data type:
my_dictionar = {
"country": "USA",
"make": "Ford",
"electric": True,
"year": 1902,
"colors": ["black", "white", "blue"]
}

print(my_dictionar)
Output:
{'country': 'USA', 'make': 'Ford', 'electric': True, 'year': 1902, 'colors': ['black', 'white', 'blue']}




Python Sets methods, difference, vs lists, pop, operation, update, documentation, index, intersection, are mutable or immutable
Python Dictionary - python

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.