You are on page 1of 2

What are the common built-in data types in Python?

There are several built-in data types in Python. Although, Python doesn't require data types to
be defined explicitly during variable declarations but type errors are likely to occur if the
knowledge of data types and their compatibility with each other are neglected. Python
provides type() and isinstance() functions to check the type of these variables. These data
types can be grouped into the following catetgories-
• None Type
None keyword represents the null values in Python. Boolean equality operation can be
performed using these NoneType objects.
Class
Description
Name
NoneTyp Represents the NULL values in
e Python

• Numeric Types
There are three distint numeric types - integers, floating-point numbers, and complex numbers.
Additionally, booleans are a sub-type of integers.
Class
Description
Name
int Stores integer literals including hex, octal and binary numbers as integers
Stores literals containing decimal values and/or exponent sign as floating-point
float
numbers
complex Stores complex number in the form (A + Bj) and has attributes: real and imag
bool Stores boolean value (True or False)
Note:  The standard library also includes fractions to store rational numbers and decimal to store
floating-point numbers with user-defined precision.
• Sequence Types
According to Python Docs, there are three basic Sequence Types - lists, tuples, and range
objects. Sequence types have the in and not in operators defined for their traversing their
elements. These operators share the same priority as the comparison operations.
Class
Description
Name
list Mutable sequence used to store collection of items.
tuple Immutable sequence used to store collection of items.
Represents an immutable sequence of numbers generated during
range
execution.
str Immutable sequence of Unicode code points to store textual data.
Note:  The standard library also includes additional types for processing:
1.  Binary data such as  bytearray bytes memoryview , and
2.  Text strings such as str .
• Mapping Types
A mapping object can map hashable values to random objects in Python. Mappings objects are
mutable and there is currently only one standard mapping type, the dictionary.
Class
Description
Name
Stores comma-separated list of key:
dict
value pairs

• Set Types
Currently, Python has two built-in set types - set and frozenset. set type is mutable and
supports methods like add() and remove(). frozenset type is immutable and can't be modified
after creation.
Class
Description
Name
Mutable unordered collection of distinct hashable
set
objects
frozenset Immutable collection of distinct hashable objects
Note:  set  is mutable and thus cannot be used as key for a dictionary. On the other hand, frozenset  is
immutable and thus, hashable, and can be used as a dictionary key or as an element of another set.

You might also like