Main Menu

Pages

Dictionary

Dictionary

A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.


Example

Create and print a dictionary:

dict = {
  "brand""Ford",
  "model""Mustang",
  "year"1964
}
print(dict)

Accessing Items

You can access the items of a dictionary by referring to its key name, inside square brackets:

Example

Get the value of the "model" key:

x = dict["model"]
print(x)
Now output
Mustang

No comments:

Post a Comment