Python (Fall 2026) Module 4-2: Operators and Expressions
Overview
Bill Moseley explains Python assignment and arithmetic operators, including how `*`, `/`, `**`, `%`, and `//` work with concrete numeric examples. He contrasts true division with floor division, introduces compound assignment, and demonstrates Python's PEMDAS order of operations with a nested expression that evaluates to 8,214.
Key takeaways
- Python uses `**` for exponentiation, so `2 ** 4` evaluates to 16; `*` is multiplication, not the exponent operator.
- The `%` operator returns a division remainder: `10 % 3` is 1, while `10 // 3` gives the integer quotient 3 for integer operands.
- True division with `/` returns a float for integer inputs, including `9 / 3`, which evaluates to `3.0`.
- Compound assignment updates a variable in place, with `x += 3` equivalent to `x = x + 3`; Python also provides the modulo form `x %= 3`.
- Python follows PEMDAS, applying multiplication and division left to right and addition and subtraction left to right; the lesson's worked expression evaluates to 8,214.
Chapters
- The single equal sign assigns a value, as in `x = 3`; it is distinct from an arithmetic expression such as `3 + 1`.
- Python uses `+` and `-` for addition and subtraction, and the asterisk `*` for multiplication.
- The forward slash `/` performs division; Moseley distinguishes it from the backslash `\`, which has a different role in computing.
- The operator `**` raises a number to a power: `2 ** 4` evaluates to 16.
- The modulo operator `%` returns the remainder, so `10 % 3` evaluates to 1; floor division `10 // 3` returns 3.
- For integer operands, `/` returns a float even when the result is whole, as with `9 / 3` producing `3.0`; `10 // 3` produces an integer.
- Compound assignment such as `x += 3` is shorthand for `x = x + 3`; Python also supports `%=` despite the lesson's claim that modulus has no compound form.
- Python applies parentheses first, then exponents, then multiplication and division from left to right, followed by addition and subtraction from left to right.
- The worked expression simplifies `4 ** 5` to 1,024, then `1,024 * 2 + 3` to 2,051 inside parentheses.
- The remaining operations include `4 * 2,051` and `30 / 6`; adding those results to 2 and 3 gives the final value 8,214.
Transcript excerpt
0:01 So let's get into operators and expressions. Operators and expressions are about manipulating data. And so let's start with an operator here. We've already used this one, right? The assignment operator is a single equal sign. And it tells us that this is equal to this. So we're taking this number, putting it in the container, we're assigning the value of that container. So in that case, x is equal to three. We'll start with the simple ones. Addition. The addition operator allows us to create an expression. Right? This is an expression. Looks like a formula. You can kind of think of it that
0:53 way. But an expression has one or more values, or two or more values, and one or two or more operators. Okay? So it has to have at least two values, x and three. x and three. This is an expression up here as well. And at least one operator. So the operators are the signs that we use to do the math. Here we go. So x = 3 + 1. What's the value of x in this expression? Four. Subtraction. We know how subtraction works. x = 3 - 1, or x = 2. Multiplication looks maybe a little bit different than what we're used to. If we're not used to programming, typically in multiplication, we use a dot, or we use an x, or some other symbol.
1:46 In programming, the symbol that we use is the asterisk. And the reason for that is because the other symbols, dots and x's and things like that, are used up by other functions. So in this case, x = 3 * 2, or the x is what? Six. Division. Now division, we're used to maybe writing something over something else. In this case, we are writing division in a linear format. So, we're using the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.