Data types are the classification or categorization of data items. Data types represent a kind of value which determines what operations can be performed on that data. Numeric, non-numeric and Boolean (true/false) data are the most used data types. However, each programming language has its own classification largely reflecting its programming philosophy.
Python has the following standard or built-in data types:
A numeric value is any representation of data which has a numeric value. Python identifies three types of numbers:
Data with one of two built-in values True
or False
. Notice that 'T' and 'F' are capital. true
and false
are not valid booleans and Python will throw an error for them.
A sequence is an ordered collection of similar or different data types. Python has the following built-in sequence data types:
A dictionary object is an unordered collection of data in a key:value pair form. A collection of such pairs is enclosed in curly brackets. For example: {1:"Steve", 2:"Bill", 3:"Ram", 4: "Farha"}
Python has an in-built function type() to ascertain the data type of a certain value. For example, enter type(1234)
in Python shell and it will return <class 'int'>
, which means 1234 is an integer value. Try and verify the data type of different values in Python shell, as shown below.
>>> type(1234)
<class 'int'>
>>> type(55.50)
<class 'float'>
>>> type(6+4j)
<class 'complex'>
>>> type("hello")
<class 'str'>
>>> type([1,2,3,4])
<class 'list'>
>>> type((1,2,3,4))
<class 'tuple'>
>>> type({1:"one", 2:"two", 3:"three"})
<class 'dict'>
Data objects of the above types are stored in a computer's memory for processing. Some of these values can be modified during processing, but contents of others can't be altered once they are created in the memory.
Number values, strings, and tuple are immutable, which means their contents can't be altered after creation.
On the other hand, collection of items in a List or Dictionary object can be modified. It is possible to add, delete, insert, and rearrange items in a list or dictionary. Hence, they are mutable objects.