Technology  /  Python

🐍 Python 78 guides · updated 2026

From first variable to OOP, generators, and real projects — the language that runs everything from data pipelines to AI agents, taught the practical way.

Python Variables and Data Types: A Practical Guide Beyond the Basics

Variables are placeholders. Data types define what kind of placeholder you have. That’s the short version. The longer version involves understanding how Python handles types differently from most compiled languages — and why that matters when you’re writing real code.


Variables in Python

A variable is created the moment you assign a value to a name. No declaration keyword, no type annotation required:

username = "alice_dev"
login_count = 47
session_active = True
last_seen = None

Python figures out the type from the value on the right-hand side. This is called dynamic typing — the type is determined at runtime, not when you write the code.

Naming rules and conventions

Python enforces these rules:

Beyond the rules, PEP 8 (Python’s style guide) recommends:

# Good naming
items_in_cart = 3
discount_rate = 0.15
final_price = items_in_cart * 100 * (1 - discount_rate)
# Hard to follow
x = 3
d = 0.15
p = x * 100 * (1 - d)

Python’s Core Data Types

Integers (int)

Whole numbers with no size limit in Python 3. You can work with arbitrarily large integers without overflow:

age = 29
population = 8_100_000_000 # underscores improve readability
factorial_20 = 2432902008176640000
print(type(age)) # <class 'int'>

Floating-point numbers (float)

Numbers with decimal points, stored as IEEE 754 double-precision values. This means they have finite precision — important to know when comparing floats:

price = 19.99
temperature = -3.7
# Floating-point precision surprise
print(0.1 + 0.2) # 0.30000000000000004
print(0.1 + 0.2 == 0.3) # False
# Use round() or math.isclose() for comparisons
import math
print(math.isclose(0.1 + 0.2, 0.3)) # True

Strings (str)

Sequences of characters, immutable, and enclosed in single or double quotes (interchangeable):

first_name = "Jordan"
last_name = 'Kim'
full_name = first_name + " " + last_name # concatenation
# f-strings for embedding variables
greeting = f"Hello, {full_name}! You have {3} messages."

Booleans (bool)

Only two values: True and False. Booleans are a subclass of int in Python — True equals 1 and False equals 0, which occasionally produces surprising arithmetic results.

is_logged_in = True
has_permission = False
# Boolean arithmetic (rarely useful but good to know)
print(True + True) # 2
print(False * 10) # 0

None

None is Python’s null value. It represents the intentional absence of a value — different from zero, empty string, or False:

result = None # hasn't been computed yet
def find_user(user_id):
# Returns a user object if found, None if not
if user_id in database:
return database[user_id]
return None

Checking Types at Runtime

type()

Returns the exact class of an object:

items = [1, 2, 3]
print(type(items)) # <class 'list'>
print(type(items) is list) # True

isinstance()

Checks whether an object is an instance of a class or a tuple of classes. Preferred over type() in most real code because it respects inheritance:

def process_number(value):
if isinstance(value, (int, float)):
return value * 2
raise TypeError(f"Expected a number, got {type(value).__name__}")
print(process_number(5)) # 10
print(process_number(3.14)) # 6.28

isinstance handles the case where value might be a subclass of int or floattype(value) is int would fail for subclasses, but isinstance correctly returns True.


Multiple Assignment and Unpacking

Python lets you assign multiple variables in a single line:

x, y, z = 10, 20, 30
a = b = c = 0 # all three point to the same value
# Useful for swapping values — no temp variable needed
x, y = y, x

Common Mistakes

Confusing None with False or 0. These are all falsy in a boolean context, but they’re not equal:

print(None == False) # False
print(None == 0) # False
print(bool(None)) # False — but None itself is not False

Reassigning to a different type. Python allows it, but it’s usually a sign of confused logic:

result = 42
result = "forty-two" # legal, but why?

Using mutable default arguments. This is a Python-specific trap worth knowing early:

# Wrong — the list is shared across all calls
def add_item(item, container=[]):
container.append(item)
return container
# Right
def add_item(item, container=None):
if container is None:
container = []
container.append(item)
return container

Understanding variables and data types well gives you a stable foundation. Python’s type system is permissive enough to move fast but strict enough to catch real errors — and once you understand the boundaries, you’ll rarely run into surprises.