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.
Python enforces naming rules at parse time, so a bad variable name causes an immediate SyntaxError before any code runs.
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 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:
= aloud as "gets" or "is assigned". Read == as "equals". That mental habit prevents most assignment-vs-equality bugs before you make them.The 4 core 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.
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.
Special operators
Order of operations
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
> 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.
* and / compute derived figures such as revenue per transaction without repeating raw spreadsheet values.== 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.= means ASSIGNMENT (store a value), == means EQUALITY (compare values)int (whole numbers), float (decimals), str (text), bool (True/False)+) joins text end-to-endsnake_case for variable names and make them descriptiveWhere 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
- 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
- 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
- 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
- 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
- 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