You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Variables are named containers that store values in your program. In Python, you create a variable simply by assigning a value to a name — no type declaration needed.
name = "Alice"
age = 30
height = 5.7
is_active = True
Python infers the type from the value on the right. Variable names are case-sensitive, so age and Age are different variables.
Strings hold text. You can use single or double quotes:
greeting = "Hello, World!"
language = 'Python'
multi = """This spans
multiple lines"""
Useful string operations:
name = "Alice"
print(len(name)) # 5 — length
print(name.upper()) # ALICE
print(name.lower()) # alice
print(name[0]) # A — indexing
print(name[1:3]) # li — slicing
count = 42 # integer
price = 9.99 # float
big = 1_000_000 # underscores for readability
is_valid = True
has_error = False
Booleans are the result of comparisons and are used in conditions.
None is Python's way of representing "no value" or "nothing":
result = None
print(result) # None
Use type() to inspect a variable's type:
x = 42
print(type(x)) # <class 'int'>
Convert between types with built-in functions:
age_str = "25"
age_int = int(age_str) # string to integer: 25
price = 9.99
price_int = int(price) # float to integer: 9 (truncates)
count = 7
count_float = float(count) # integer to float: 7.0
number = 42
number_str = str(number) # integer to string: "42"
Valid variable names:
By convention, Python uses snake_case for variable names:
first_name = "Alice"
total_price = 99.99
max_retries = 3
Python lets you assign multiple variables at once:
x, y, z = 1, 2, 3
a = b = c = 0 # all three set to 0
Understanding data types is fundamental — every value in Python has a type, and knowing the type tells you what operations are valid.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.