Data Types in Python

Data types define the kind of value a variable can hold. Python automatically determines the data type based on the value assigned.

πŸ’‘ Python is dynamically typed β€” you don’t need to specify data types explicitly.

Common Built-in Data Types

  • int – Integer numbers (e.g. 10)
  • float – Decimal numbers (e.g. 3.14)
  • str – Text or strings (e.g. "Python")
  • bool – True or False

Example

x = 10
price = 99.5
name = "Khushi"
is_active = True

print(type(x))
print(type(price))
print(type(name))
print(type(is_active))

Type Conversion

Python allows converting one data type to another using built-in functions.

x = "100"
y = int(x)
z = float(y)

print(y, z)

Common Mistakes

❌ Mixing incompatible data types
❌ Forgetting to convert user input (string) to numbers

Practice Exercises

  1. Create variables of type int, float, and string
  2. Print their values and data types