PYTHON Tutorial



DATA TYPES IN PYTHON


๐Ÿ”ข Python Data Types

In Python, every value has a **data type**. Python automatically assigns the data type when a value is assigned to a variable.

๐Ÿงฎ Basic Built-in Data Types

  • int - Integer numbers
  • float - Decimal numbers
  • str - String/text
  • bool - Boolean values (True or False)
  • list - Ordered, mutable collection
  • tuple - Ordered, immutable collection
  • set - Unordered, unique collection
  • dict - Key-value pairs

๐Ÿ” Examples

# 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'>
  

๐Ÿ“ฆ Dynamic Typing

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
  

๐Ÿงช Check Data Type

Use the type() function to check any variable's data type.

print(type(100))       # <class 'int'>
print(type("hello"))   # <class 'str'>
  
๐Ÿง  Note: Python automatically assigns the appropriate data type, but you can also convert types using int(), str(), float(), etc.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review