BeginnerPython · 27 min · 21 challenges

Python Expressions: Beginner

NASA's Jet Propulsion Laboratory uses Python to command Mars rovers and process terabytes of telescope data, and one of the core reasons they chose it is the clean, unambiguous syntax that lets dozens of scientists and engineers collaborate on mission-critical code without misreading each other's work. When a line of code could trigger a command 140 million miles away, there is no room for a misplaced bracket or an indentation error that changes meaning silently. Python's strict indentation rules force a program's layout to match its logic, so a bug shows up in the structure instead of hiding in syntactic noise. JPL engineers rely on the same syntax rules this lesson covers, on code where a misread line can cost a 2.5-billion-dollar spacecraft.

How Computers Store Data

Daily Life
Interviews
Variables live in memory, so start there. A computer has 2 main types of storage:
Hard Drive / SSD
Hard Drive / SSD
Permanent storage that keeps data even when power is off. This is where your files live.
RAM (Memory)
RAM (Memory)
Temporary, ultra-fast storage used while programs run. Data disappears when the program ends.
When you run a Python program, it uses RAM to store all the data it needs. RAM is a large grid of small storage slots, each with a unique address.
Each slot can hold a small piece of data. When you create a variable in Python, you're essentially telling the computer: "Reserve some of these memory slots for me, and let me refer to them by this name."

Python enforces naming rules at parse time, so a bad variable name causes an immediate SyntaxError before any code runs.

Every piece of data your program works with lives in a named memory slot.
TIP
Use descriptive names from the start. "count" is fine; "c" is not.

Variables and Naming

Daily Life
Interviews
A variable is a named container for storing data in your computer's memory. The name "variable" comes from the fact that the value it holds can vary (change) during the program.

The labeled box analogy

Take a warehouse full of boxes, each with a label on the front. The label is the variable name, and the contents of the box are the value.
When you want to find something, you look for the label. When you want to change what's stored, you replace the contents of that labeled box. You don't need to know exactly where in the warehouse the box is located; the label handles that for you.
user_name = "Maya"
user_age = 28
print(user_name)
print(user_age)
>>>Output
Maya
28

What happens in memory

When Python executes the line user_name = "Maya", several things happen:

01
Find memory
Python finds available memory slots large enough to store the 4-character string value.
02
Write the data
It writes the characters M, a, y, a into those memory slots.
03
Create a reference
It creates a link from the name "user_name" to that memory location.
04
Look up by name
Whenever you use user_name, Python knows where to find the data.
You don't need to manage any of this yourself. Python handles all the memory details automatically. That's one reason Python is considered beginner-friendly compared to languages like C or C++.

Python naming conventions

Variable names in Python have rules (requirements) and conventions (recommendations). Breaking rules causes errors. Ignoring conventions makes code hard to read.
Rules (must follow)
  • Must start with a letter or underscore (_)
  • Can only contain letters, numbers, and underscores
  • Cannot be a Python keyword (like if, for, while)
  • Case-sensitive: "Name" and "name" are different variables
Valid variable names:
user_name = "Maya"
_private_data = 42
score2 = 100
firstName = "Alex"
print(user_name, _private_data, score2, firstName)
>>>Output
Maya 42 100 Alex
Invalid names that cause errors:
2nd_place = "silver"
user-name = "Maya"
my variable = 10
for = 5

These fail because: names can't start with numbers, can't use hyphens, can't have spaces, and can't use reserved keywords like for.

Python uses snake_case for variable names: all lowercase letters with underscores separating words. This is a convention, not a rule, but virtually all Python programmers follow it.

•Pythonic
  • user_count
  • total_revenue
  • is_logged_in
  • max_retry_attempts
•Not Pythonic
  • userCount (camelCase)
  • TotalRevenue (PascalCase)
  • USERCOUNT (SCREAMING)
  • u, x, temp1 (unclear)
TIP
Good variable names describe WHAT the data represents. "customer_count" is better than "c" or "num" because anyone reading the code instantly understands what it holds.
Hyphens are arithmetic operators in Python, so "my-name" is parsed as subtraction, not a variable name. Multi-word names use the _ character as the separator instead.
The snake_case convention makes Python code immediately recognizable. The standard library uses it too, so your names read the same way as the functions you call from it.

Assignment vs. Equality

Daily Life
Interviews

This is one of the most common points of confusion for beginners. In Python (and most programming languages), the = symbol does NOT mean "equals" in the mathematical sense. It means assignment.

•Math class
  • x = 5 means "x equals 5"
  • 5 = x also valid (same thing)
  • States a fact about equality
•Python
  • x = 5 means "assign 5 to x"
  • 5 = x is an ERROR (invalid)
  • Performs an action (stores data)

Read x = 5 as "x gets the value 5" or "assign 5 to x". The value on the right flows into the variable on the left.

score = 100
score = score + 1
print(score)
>>>Output
101
After this, score is 101. This would be nonsense in math (100 = 101?), but in programming it makes perfect sense: "Take the current value of score, add 1, store the result back in score."

So how do I check equality?

To actually check if two things are equal, Python uses == (two equals signs). This is called the equality operator.

Assignment stores a value:
x = 5

Comparison asks a question and returns True or False:

x = 5
print(x == 5)
print(x == 10)
>>>Output
True
False
The first returns True ("Is x equal to 5?" Yes!). The second returns False.
Using the correct operator in conditions:
x = 5
if x == 5:
print("x is five")
>>>Output
x is five
Confusing = with == is one of the most common beginner bugs. In Python, assignment always flows right to left: the value on the right is stored into the variable on the left.
Every time you write a condition in an if-statement or while-loop, you need == to compare. Every time you store a value, you need =. With practice, this distinction becomes automatic.
TIP
Read = aloud as "gets" or "is assigned". Read == as "equals". That mental habit prevents most assignment-vs-equality bugs before you make them.

Data Types and Strings

Daily Life
Interviews
Every piece of data in your program has a type. The type determines what you can do with that data and how the computer stores it in memory.
Think about the number "5" and the text "5". They look the same, but they are different types:
number_five = 5
text_five = "5"
They behave completely differently:
number_five = 5
text_five = "5"
print(number_five + 10)
print(text_five + "10")
>>>Output
15
510
The first gives 15 (mathematical addition). The second gives "510" (text concatenation). Trying text_five + 10 causes an error because you can't add text and a number directly.
Data types exist because computers need to know how to interpret the 1s and 0s stored in memory. The same binary pattern could represent a number, a letter, or something else entirely, depending on its type.

The 4 core types

Python has many data types, but almost every program uses these 4:
int
Whole numbers
Counting and indexing
float
Decimal values
Measurements, percentages
str
Text strings
Names, messages, any text
bool
True or False
Conditions, flags, logic
TIP
Floats have limited precision. Very small decimal differences can occur in calculations. For money, many professionals use integers representing cents instead of floats representing dollars.

Checking data types

You can check any value's type using the type() function. This is useful when debugging or when you're unsure what type a variable holds.

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

Working with strings

Strings are one of the most commonly used data types. Python lets you use single quotes, double quotes, or triple quotes:
name = 'Maya'
name = "Maya"
message = "She said 'hello'"
paragraph = """This is a long string
that spans multiple lines."""

What is concatenation?

Concatenation means joining strings together. When you use the + operator with strings, instead of adding numbers, it glues the strings end-to-end.

first_name = "Maya"
last_name = "Johnson"
full_name = first_name + " " + last_name
greeting = "Hello, " + first_name + "!"
print(full_name)
print(greeting)
>>>Output
Maya Johnson
Hello, Maya!
You can only concatenate strings with strings. Trying to concatenate a string with a number causes an error. You'll learn how to convert between types later.
Python is strongly typed, meaning it never silently converts between types. This strict behavior prevents subtle bugs that occur in languages that allow mixed-type operations.
When Python raises a TypeError, it is telling you exactly where you mixed incompatible types.

Operators and Readability

Daily Life
Interviews
Python provides operators for mathematical calculations. Most work exactly like you'd expect from math class, but a few have special behaviors.
01
+ Addition
5 + 3 equals 8. Adds 2 values together.
02
- Subtraction
10 - 4 equals 6. Subtracts right from left.
03
* Multiplication
7 * 6 equals 42. Multiplies 2 values.
04
/ Division
15 / 4 equals 3.75. Always returns a float.
total = 100 + 50
difference = 100 - 30
product = 25 * 4
quotient = 100 / 8
print(total)
print(difference)
print(product)
print(quotient)
>>>Output
150
70
100
12.5

Special operators

Python has 3 more arithmetic operators:
//  Floor division
// Floor division
Divides and rounds DOWN to the nearest integer. 15 // 4 equals 3.
%  Modulo (remainder)
% Modulo (remainder)
Returns the remainder after division. 15 % 4 equals 3.
**  Exponent (power)
** Exponent (power)
Raises a number to a power. 2 ** 10 equals 1024.
Floor division for whole numbers:
hours = 125 // 60
pages = 45 // 10
print(hours)
print(pages)
>>>Output
2
4
125 minutes = 2 complete hours. 45 items = 4 complete pages of 10.
Modulo for remainders:
remainder = 125 % 60
print(remainder)
number = 8
is_even = number % 2 == 0
print(is_even)
>>>Output
5
True

Order of operations

Python follows the standard mathematical order of operations (PEMDAS): Parentheses, Exponents, Multiplication/Division, Addition/Subtraction.
result = 2 + 3 * 4
print(result)
>>>Output
14
Result is 14, not 20. Multiplication happens first (3 * 4 = 12), then addition (2 + 12 = 14). When in doubt, use parentheses for clarity.

Comments and readable code

Comments are notes in your code that Python completely ignores. They exist only for humans reading the code.
# Track users
user_count = 150
Comments explain WHY, not WHAT. Bad: "# Add 1 to x". Good: "# Compensate for zero-based indexing".
✓Do
  • customer_total = price * quantity
  • is_valid = "@" in email
  • days_left = deadline - today
✗Don't
  • ct = p * q
  • v = "@" in e
  • d = dl - t
6 months from now, you'll return to code you wrote and have no memory of why you wrote it that way.
Readable code starts with good names. Fix the poorly named variable below to make the code self-documenting.
Stale comments are worse than no comments. A comment that contradicts the code misleads whoever reads it next about what the code does.
Everything else in this course builds on arithmetic, clear naming and honest comments.
TIP
When you change code, update its comments in the same commit. Treat comments as part of the code.
❯❯❯PUTTING IT ALL TOGETHER

> You are a junior data engineer at Stripe writing your first Python script to pull daily transaction counts from a spreadsheet and print a formatted summary to the console. The script must name each metric clearly, compute derived values, validate ranges, and produce readable terminal output.

Variables store each transaction metric (total, count, average) so values are named and reusable throughout the automation script.
Arithmetic operators like * and / compute derived figures such as revenue per transaction without repeating raw spreadsheet values.
Assignment vs. equality matters when == checks that a count is within expected bounds before the script proceeds to print.
print() outputs each formatted summary line so the daily automation produces human-readable console results for the team.
KEY TAKEAWAYS
Variables are named containers that store values in memory
= means ASSIGNMENT (store a value), == means EQUALITY (compare values)
4 core types: int (whole numbers), float (decimals), str (text), bool (True/False)
Data types determine what operations are allowed on values
String concatenation (+) joins text end-to-end
Use snake_case for variable names and make them descriptive
Comments explain WHY code exists, not what it does

Where every Python journey begins

Category
Python
Difficulty
beginner
Duration
27 minutes
Challenges
21 hands-on challenges

Topics covered: How Computers Store Data, Variables and Naming, Assignment vs. Equality, Data Types and Strings, Operators and Readability

Lesson Sections

  1. How Computers Store Data (concepts: pyVariables)

    Variables live in memory, so start there. A computer has 2 main types of storage: When you run a Python program, it uses RAM to store all the data it needs. RAM is a large grid of small storage slots, each with a unique address. Each slot can hold a small piece of data. When you create a variable in Python, you're essentially telling the computer: "Reserve some of these memory slots for me, and let me refer to them by this name." Every piece of data your program works with lives in a named memor

  2. Variables and Naming (concepts: pyVariables)

    A variable is a named container for storing data in your computer's memory. The name "variable" comes from the fact that the value it holds can vary (change) during the program. The labeled box analogy Take a warehouse full of boxes, each with a label on the front. The label is the variable name, and the contents of the box are the value. When you want to find something, you look for the label. When you want to change what's stored, you replace the contents of that labeled box. You don't need to

  3. Assignment vs. Equality (concepts: pyVariables)

    After this, score is 101. This would be nonsense in math (100 = 101?), but in programming it makes perfect sense: "Take the current value of score, add 1, store the result back in score." So how do I check equality? Assignment stores a value: The first returns True ("Is x equal to 5?" Yes!). The second returns False. Using the correct operator in conditions: Confusing = with == is one of the most common beginner bugs. In Python, assignment always flows right to left: the value on the right is st

  4. Data Types and Strings (concepts: pyDataTypes)

    Every piece of data in your program has a type. The type determines what you can do with that data and how the computer stores it in memory. Think about the number "5" and the text "5". They look the same, but they are different types: They behave completely differently: The first gives 15 (mathematical addition). The second gives "510" (text concatenation). Trying text_five + 10 causes an error because you can't add text and a number directly. Data types exist because computers need to know how

  5. Operators and Readability (concepts: pyArithmetic)

    Python provides operators for mathematical calculations. Most work exactly like you'd expect from math class, but a few have special behaviors. Special operators Python has 3 more arithmetic operators: Floor division for whole numbers: 125 minutes = 2 complete hours. 45 items = 4 complete pages of 10. Modulo for remainders: Order of operations Python follows the standard mathematical order of operations (PEMDAS): Parentheses, Exponents, Multiplication/Division, Addition/Subtraction. Result is 14