Python Dictionary Datatypes

aimtocode

DataType Definition

Data types are means to identify the type of data and associated operations for handling it. In python, we need not to define the type of the variable while declaring it. The interpreter implicitly binds the value with its type accordingly.

Data types represent a kind of value which determines what operations can be performed on that given data.


DICTIONARIES DataType

Dictionaries are one of Python‘s best features; they are the building blocks of many efficient and elegant algorithms.

A Dictionary is a Mapping: A dictionary is like a list, but more general. In a list, the indices have to be integers; in a dictionary they can be (almost) any type.

A dictionary contains a collection of indices, which are called keys, and a collection of values. Each key is associated with a single value. The association of a key and a value is called a key-value pair or sometimes an item.

In mathematical language, a dictionary represents a mapping from keys to values, so you can also say that each key ―maps to‖ a value. As an example, we‘ll build a dictionary that maps from English to Tamil words, so the keys and the values are all strings.

The function dict creates a new dictionary with no items. Because dict is the name of a built-in function, you should avoid using it as a variable name.

Creates Dictionary



Output:

 1st name is Prayag
 2nd name is Ritesh
 {1: 'Prayag', 2: 'Sujeet', 3: 'Rahul', 4: 'Ritesh'}
 dict_keys([1, 2, 3, 4])
 dict_values(['Prayag', 'Sujeet', 'Rahul', 'Ritesh'])


Read Also:


aimtocode