In Python, a data type defines the type of value that a variable can store. Since Python is a dynamically typed language, you do not need to declare the data type explicitly—Python automatically determines it.
Python data types can be broadly classified into:
Used to store numbers.
int)x = 10
float)y = 3.14
complex)z = 2 + 3j
Used to store a collection of items in order.
str)name = "Python"
list)numbers = [1, 2, 3]
tuple)data = (1, 2, 3)
set)values = {1, 2, 3}
dict)student = {"name": "Rahul", "age": 20}
bool)x = True
y = False
NoneType)x = None
Use the type() function:
x = 10
print(type(x))
Output
<class 'int'>
x = "10"
y = int(x)
print(y)
| Data Type | Description | Example |
|---|---|---|
int |
Integer | 10 |
float |
Decimal | 3.14 |
complex |
Complex number | 2+3j |
str |
String | "Hello" |
list |
Ordered, mutable | [1,2,3] |
tuple |
Ordered, immutable | (1,2,3) |
set |
Unique elements | {1,2,3} |
dict |
Key-value pairs | {"a":1} |
bool |
True/False | True |
NoneType |
No value | None |
type() to check data typeData types are the foundation of Python programming. Understanding them helps in: