Variables & Types
int, float, str, bool, None, and dynamic typing
Skills taught: python.variables, python.types, python.type-conversion
Variables and assignment
# Assign a value to a variable
name = 'Prashant'
age = 28
height = 5.9
is_student = True
notes = None # no value yet
# Print variables
print(name) # Prashant
print(age) # 28
# Multiple assignment
x = y = z = 0
# Tuple unpacking — assign multiple at once
lat, lon = 28.6, 77.2
print(lat, lon) # 28.6 77.2
# Swap without a temp variable
a, b = 10, 20
a, b = b, a
print(a, b) # 20 10
Python's core types
# int — whole numbers (no size limit)
count = 42
big = 1_000_000 # underscores for readability
negative = -7
# float — decimal numbers (IEEE 754)
price = 9.99
pi = 3.14159
# str — text (single or double quotes, immutable)
greeting = 'Hello'
path = "C:/Users/prashant"
multiline = '''Line one
Line two'''
# bool — True or False (capital T and F!)
is_active = True
has_errors = False
# None — absence of value
result = None
# Check type
print(type(42)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type('hello')) # <class 'str'>
print(type(True)) # <class 'bool'>
print(type(None)) # <class 'NoneType'>
Type conversion
# Convert between types
num_str = '42'
num_int = int(num_str) # '42' → 42
num_float = float('3.14') # '3.14' → 3.14
text = str(100) # 100 → '100'
bool_val = bool(0) # 0 → False
bool_val2 = bool('hello') # non-empty string → True
# input() always returns a string — convert it!
age_str = '25' # pretend this came from input()
age_int = int(age_str)
print(age_int + 1) # 26 (would fail without int())
# Falsy values (all evaluate to False in boolean context)
# 0, 0.0, '', [], {}, set(), None
Frequently Asked Questions
Do I need to declare the type of a variable in Python?
No. Python is dynamically typed — you just write x = 42 and Python knows it's an int. You can optionally add type hints (x: int = 42) for documentation and tooling, but Python doesn't enforce them at runtime.
What is the difference between = and ==?
= is assignment (x = 5 stores 5 in x). == is comparison (x == 5 asks 'is x equal to 5?' and returns True or False). This is the same in most languages.