🐍 Python 2026 › Lesson 3: Variables and Data Types
Lesson 3 of 30

Variables and Data Types

Integers, floats, strings, booleans, and how Python's dynamic typing works.

What is a Variable?

A variable is a named container that stores a value. Unlike many languages, Python does not require you to declare a variable's type — Python infers it automatically.

age = 25            # integer
price = 9.99         # float
name = "Alice"       # string
is_student = True   # boolean

Core Data Types

TypeKeywordExample
Integerint42
Floatfloat3.14
Stringstr"Hello"
BooleanboolTrue / False
NoneNoneTypeNone

Checking the Type

Use the built-in type() function to inspect any value:

print(type(42))       # <class 'int'>
print(type(3.14))     # <class 'float'>
print(type("hi"))    # <class 'str'>
print(type(True))    # <class 'bool'>

Type Conversion

x = "10"
y = int(x)       # "10" → 10
z = float(x)     # "10" → 10.0
s = str(99)       # 99 → "99"

Naming Rules

⚠️ Convention
Python convention (PEP 8) uses snake_case for variable names: student_name, total_price. Avoid single-letter names except in short loops.