Number

Number data type stores numerical values only. It is further classified into three different types:

int, float and complex. Boolean data type (bool) is a subtype of integer. It is a unique data type,


consisting of two constants, True and False. Boolean True value is non-zero, non-null and non-

empty. Boolean False is the value zero.


Numeric data types

Let us execute few statements in interactive mode of Python IDLE to determine the data type of the

variable using built-in function type ().

Variables of simple data types like integer, float, Boolean that hold single value. But such variables are

not useful to hold a long list of information, such as months in a year, student names in a class, names

and numbers in a phone book or the list of artifacts in a museum. For this, Python provides other data

types like tuples, lists, dictionaries and sets.

Sequence

A Python sequence is an ordered collection of items, where each item is indexed by an integer. The three

types of sequence data types available in Python are Strings, Lists and Tuples. We will learn about each

of them in detail in later chapters. A brief introduction to these data types is as follows:

String – String is a group of characters. These characters may be alphabets, digits or special characters

including spaces. String values are enclosed either in single quotation marks (e.g.,  ̳Hello‘) or in double

quotation marks (e.g., ―Hello‖). The quotes are not a part of the string; they are used to mark the

beginning and end of the string for the interpreter. For example,

>>> str1 = 'Hello Friend'

>>> str2 = "452"

It is not possible to perform numerical operations on strings, even when the string contains a numeric

value, as in str2.

List – List is a sequence of items separated by commas and the items are enclosed in square

brackets [ ].

Tuple – Tuple is a sequence of items separated by commas and items are enclosed in parenthesis

(). This is unlike list, where values are enclosed in brackets []. Once created, we cannot change the

tuple.

Set

Set is an unordered collection of items separated by commas and the items are enclosed in curly

brackets { }. A set is similar to list, except that it cannot have duplicate entries. Once created,

elements of a set cannot be changed.


In the above example, set1 is a collection of 5 integers. The set2 is collection of different data

types of elements. You must have noticed that elements of set2 have been displayed in an order

different from the order in which they have entered. Reason of this is that set is unordered. If you

run the same code again, it is possible that you will get an output with the elements arranged in a

different order. 

None

None is a special data type with a single value. It is used to signify the absence of value in a

situation. None supports no special operations, and it is neither False nor 0 (zero).

Mapping

Mapping is an unordered data type in Python. Currently, there is only one standard mapping data

type in Python called dictionary.

Dictionary

Dictionary in Python holds data items in key-value pairs. Items in a dictionary are enclosed in

curly brackets { }. Dictionaries permit faster access to data. Every key is separated from its value

using a colon (:) sign. The key: value pairs of a dictionary can be accessed using the key. The keys

are usually strings and their values can be any data type. In order to access any value in the

dictionary, we have to specify its key in square brackets [].