LDictionary in Python
In this articles, we will look to Dictionary variables in Python.
In earlier article, we saw that variables are memory locations to keep values. When a variable declared in Python, a space is allocated in memory. Then interpreter takes memory and decides what can be stored in the memory area. We can store integers, decimals or char acters in the variables we declare in Python. In Python variables do not need an explicit declaration to for memory space. The declaration is automatic when we create and assign a value to a variable. The equal sign = is used to assign values to variables.
Dictionaries are a compund type variable similar to C, C++ and C# arrays but can store different type of variables like int, string and others.
Python dictionaries contain values like key-pairs. A dictionary key can be any Python type. Mainly numbers or string s. Value can be any arbitrary Python object.
Dictionary are declared as follows:
dict_planets = {}
dict_planets["one"] = "Mercury"
dict_planets["two"] = "Neptune"
print(dict_planets)
Lets see Python Dictionary variables in an example.
In above example, we created a Dictionary variable in Python and print it to terminal.