Variables, Data Types and Type Conversion
A variable is a name that points to a value stored in memory. Unlike languages such as Java or C++, Python never asks you to declare a variable’s type up front — it figures the type out automatically based on whatever value you assign, and that type can even change later if you assign something new to the same name.
age = 25 # int
price = 19.99 # float
name = "Tutoline" # str
is_active = True # bool
Core built-in types
int— whole numbers, positive or negative, with no size limit beyond your computer’s memoryfloat— decimal numbers, including numbers written in scientific notation like1.5e3str— text, wrapped in single or double quotes; Python treats both the same waybool— exactly two values,TrueorFalse, always capitalized
Every value in Python also has an identity and is itself an object, even something as simple as the number 5 — this is part of why Python is described as “everything is an object,” and it becomes more relevant once you reach the classes lesson later in this course.
Checking and converting types
print(type(age)) # <class 'int'>
height_str = "180"
height_cm = int(height_str) # convert str -> int
print(height_cm + 5) # 185
A very common beginner mistake is trying to combine a number and a piece of text directly, like "Age: " + 25 — Python raises a TypeError because it refuses to silently guess what you meant. You either need to convert the number to a string first with str(25), or use an f-string (as shown in the previous lesson) which handles the conversion for you automatically.
Naming rules
Variable names can contain letters, numbers, and underscores, but can’t start with a number, and can’t be one of Python’s reserved keywords like class or for. Python convention is snake_case for variables and functions (words separated by underscores, all lowercase) — stick to it so your code reads consistently with everyone else’s Python code, including the standard library itself.
Constants (by convention)
Python doesn’t have a built-in way to make a variable truly unchangeable, but by convention, a variable meant to stay constant is written in ALL_CAPS:
MAX_ATTEMPTS = 3
TAX_RATE = 0.18
Nothing stops you from reassigning MAX_ATTEMPTS later, but writing it in caps signals to anyone reading your code — including future you — that it’s meant to stay fixed.