15 min read

Variables and Data Types

Understand how to store and work with different types of data in Python.

Variables in Python

A variable is a named container that stores a value. In Python, you create a variable by assigning a value to a name using the = operator.

python
# Creating variables
name = "Alice"
age = 25
height = 5.7
is_student = True

print(name)    # Alice
print(age)     # 25
print(height)  # 5.7

Python Data Types

  • str — Text strings: "Hello", 'World'
  • int — Whole numbers: 42, -10, 0
  • float — Decimal numbers: 3.14, -0.5
  • bool — True or False
  • list — Ordered collection: [1, 2, 3]
  • dict — Key-value pairs: {"name": "Alice"}
  • tuple — Immutable sequence: (1, 2, 3)
  • None — Represents absence of value
python
# Check the type of a variable
name = "Alice"
age = 25
pi = 3.14159
is_active = True

print(type(name))      # <class 'str'>
print(type(age))       # <class 'int'>
print(type(pi))        # <class 'float'>
print(type(is_active)) # <class 'bool'>
💡

Python is dynamically typed — you do not need to declare the type of a variable. Python figures it out automatically.

🧠Quick Check

What type is the value 3.14 in Python?

🔒
Track your progress
Sign in to mark lessons complete and save your learning journey
Sign In →
Up Next
Control Flow: if, elif, else
Continue Learning
SenseCentral — Knowledge, Tools & Intelligence for Technology, Money, Business and Engineering