In our previous Python tutorial, we have explained about File Handling in Python. In this tutorial, we will discuss about Data Types in Python.
The data types are important in any programming language. The variables can store values and every vaue has data types. As Python is a dynamically typed language, so we do not need to define the type of the variable while declaring vairable as the interpreter implicitly binds the value with its type.
In spite of dynamically typed language, Python still provided some build-in data types that define the storage method on each of them.
Here is the list of some standard data types in Python.
- Numbers
- String
- List
- Tuple
- Set
- Dictionary
Numbers
In Python, the numbers has mainly three types that inlcudes Integer, Float, and Complex. We can use the method type()
to know to which class the variable belongs.
In below example code, we are assigning number and display variable type as ‘Int’.
number = 50 print(number, " is of type", type(number))
Output:
5 is of type <class 'int'>
In below example code, we are assigning float number and display variable type as ‘float’.
number = 10.5 print(number, " is of type", type(number))
Output:
10.5 is of type <class 'float'>
In below example code, we are assigning value as ’10+30j’ and display variable type as ‘complex’.
number = 10+30j print(number, " is of type", type(number))
Output:
(10+30j) is of type <class 'complex'>