In Python, every value has a **data type**. Python automatically assigns the data type when a value is assigned to a variable.
# Integer
x = 10
print(type(x)) # <class 'int'>
# Float
y = 3.14
print(type(y)) # <class 'float'>
# String
name = "Python"
print(type(name)) # <class 'str'>
# Boolean
is_ready = True
print(type(is_ready)) # <class 'bool'>
# List
colors = ["red", "blue", "green"]
print(type(colors)) # <class 'list'>
# Tuple
points = (4, 5, 6)
print(type(points)) # <class 'tuple'>
# Set
unique_values = {1, 2, 3}
print(type(unique_values)) # <class 'set'>
# Dictionary
student = {"name": "John", "age": 20}
print(type(student)) # <class 'dict'>
Python is dynamically typed, so you donโt need to declare a data type. Python figures it out automatically.
data = 42 # int data = "Now text" # str
Use the type() function to check any variable's data type.
print(type(100)) # <class 'int'>
print(type("hello")) # <class 'str'>
int(), str(), float(), etc.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!