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 and readable structure force programs to look exactly like their logic, making bugs visible at a glance rather than hidden in syntactic noise. The syntax fundamentals you practice in this lesson are the same foundation that JPL engineers rely on when the cost of a misunderstood line of code is a 2.5-billion-dollar spacecraft.
How Computers Store Data
Understand how values live in memory
> A variable name must follow Python rules. Pick the name that is valid Python and see what happens.
= 42 print()
Python enforces naming rules at parse time, so a bad variable name causes an immediate SyntaxError before any code runs.
Variables and Naming
Name variables clearly and correctly
The Labeled Box Analogy
What Happens in Memory
When Python executes the line user_name = "Maya", several things happen:
Python Naming Conventions
- 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
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.
- user_count
- total_revenue
- is_logged_in
- max_retry_attempts
- userCount (camelCase)
- TotalRevenue (PascalCase)
- USERCOUNT (SCREAMING)
- u, x, temp1 (unclear)
> This variable name breaks Python naming rules. Remove the invalid tile to fix the syntax error.
SyntaxError: invalid syntax
Assignment vs. Equality
Distinguish setting values from comparing them
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.
- x = 5 means "x equals 5"
- 5 = x also valid (same thing)
- States a fact about equality
- 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.
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.
Comparison asks a question and returns True or False:
> This code tries to assign 5 to x but has an extra equals sign. Remove the extra tile to fix it.
SyntaxError: invalid syntax
Data Types and Strings
Handle text alongside numbers and booleans
The Four Fundamental Types
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.
> Each value in Python has a type. Pick different values to see what type Python assigns.
x = print(type(x))
Working with Strings
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.
> The + operator behaves differently with numbers versus strings. Pick values to see how Python handles each combination.
a = b = print(a + b)
Operators and Readability
Write expressions that others can follow
Special Operators
Order of Operations
> Python has three division-related operators. Pick one to see what 7 divided by 2 gives you.
result = 7 2 print(result)
Comments and Readable Code
- customer_total = price * quantity
- is_valid = "@" in email
- days_left = deadline - today
- ct = p * q
- v = "@" in e
- d = dl - t
> The comment says "sum" but the code does multiplication. Remove the misleading comment tile.
The comment says "sum" but the code does multiplication
> 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.
== checks that a count is within expected bounds before the script proceeds to print.int (whole numbers), float (decimals), str (text), bool (True/False)Where every Python journey begins
- Category
- Python
- Difficulty
- beginner
- Duration
- 27 minutes
- Challenges
- 0 hands-on challenges
Topics covered: How Computers Store Data, Variables and Naming, Assignment vs. Equality, Data Types and Strings, Operators and Readability
Lesson Sections
- How Computers Store Data
Before we can understand variables, we need to understand memory. Your computer has two main types of storage: When you run a Python program, it uses RAM to store all the data it needs. Think of RAM as a massive grid of tiny storage slots, each with a unique address (like a house number on a street). 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
- Variables and Naming
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 Imagine you have a warehouse full of boxes. Each box can hold something, and each box has a label on the front. The label is the variable name. The contents inside the box is the value. When you want to find something, you look for the label. When you want to change what's stored, you replace the
- Assignment vs. Equality
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
- Data Types and Strings
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're fundamentally different: 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 k
- Operators and Readability
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 three additional arithmetic operators that are incredibly useful: 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/Divisio