A5. Python Data Types

This tutorial will guide you through the various data types available in Python, and provide examples to help you understand their usage.

Understanding data types is crucial in programming, as they determine the kind of information that can be stored in a variable. For instance, in the following example, the variable “num” is assigned the integer value of 24:

num = 24

As a result, the data type of “num” is of the int class.

Python Data Types

Data TypesClassesDescription
Numericint, float, complexholds numeric values
Stringstrholds sequence of characters
Sequencelist, tuple, rangeholds collection of items
Mappingdictholds data in key-value pair form
Booleanboolholds either True or False
Setset, frozeensethold collection of unique items

In Python programming, all entities are represented as objects, with data types being classes and variables being instances of these classes.

Python Numeric Data type

In Python, the numeric data type is utilized to store numerical values. This includes integers, floating-point numbers, and complex numbers, which are defined as int, float, and complex classes in Python.

The int class is used to hold signed integers of unlimited length, while the float class is used to hold numbers with decimal points and has a level of accuracy of up to 15 decimal places. The complex class is used to hold complex numbers.

We can easily determine the class a variable or value belongs to by using the type() function. For example, if we want to know the class of the variable x, we can simply use the type(x) function.