Engineering Python · Language Basics
Expressions and Operators
In Engineering Python because every formula in a lab is an expression — arithmetic, comparison and string ops are the calculators you will reuse.
Expressions compute values. Arithmetic operators combine numbers; comparisons yield booleans; some operators work on strings too. Parentheses control order when precedence is unclear.
- Engineering Python
- Easy level
- 4 concepts
1Arithmetic operators
`+ - * /` do the usual arithmetic. `/` always yields a float in Python 3. `//` is floor division; `%` is remainder; `**` is power.
Figure. / always yields a float. // is floor division; % is remainder; ** is power.
Division flavours
print(7 / 2)
print(7 // 2)
print(7 % 2)
print(2 ** 3)What is `7 // 2` in Python 3?
- 3
- 3.5
- 1
Floor division discards the fractional part toward -inf for positives here yielding 3.
2Comparisons are booleans
`== != < <= > >=` compare values and return `True` or `False`. These feed `if` later.
Figure. Comparisons return True or False. These booleans later feed if.
Takeaway
- Idea`== != < <= > >=` compare values and return `True` or `False`. These feed `if` later.
Compare
print(3 < 5)
print(3 == 5)What is the boolean evaluation of the expression (5 > 3) and (2 == 4)?
- True, because at least one operand is truthy
- None, because comparison operators return void
- An error, because parentheses cannot group logical expressions
- False, because the right operand 2 == 4 evaluates to false
In an and conjunction, both sides must be True. Here (True and False) evaluates to False.
3String operators
`+` concatenates strings. `*` repeats a string. You cannot add a number to a string without casting.
Figure. + concatenates strings. * repeats a string. You cannot add a number to a string without casting.
Takeaway
- Idea`+` concatenates strings. `*` repeats a string. You cannot add a number to a string without casting.
Concatenate and repeat
print("lab-" + "01")
print("na" * 3)4Lab: evaluate expressions
Compute a small formula and print it so the check can see the result.
Figure. Parentheses make the intended order obvious. (3 + 4) * 2 prints 14.
Takeaway
- IdeaCompute a small formula and print it so the check can see the result.
Coding lab. Evaluate a formula runs in the app, with checks on your output.
Notes
- In Engineering Python because every formula in a lab is an expression — arithmetic, comparison and string ops are the calculators you will reuse.
- `+ - * /` do the usual arithmetic. `/` always yields a float in Python 3. `//` is floor division; `%` is remainder; `**` is power.
- `== != < <= > >=` compare values and return `True` or `False`. These feed `if` later.
Exam traps & shortcuts
- Run one cell at a time and read stdout before changing more lines.
- Names are labels for values; rebinding a name does not rewrite old prints.
Recap
Expressions compute; comparisons yield bools; string + concatenates.
- Arithmetic operators
- `+ - * /` do the usual arithmetic. `/` always yields a float in Python 3. `//` is floor division; `%` is remainder; `**` is power.
- Comparisons are booleans
- `== != < <= > >=` compare values and return `True` or `False`. These feed `if` later.
- String operators
- `+` concatenates strings. `*` repeats a string. You cannot add a number to a string without casting.
- Lab: evaluate expressions
- Compute a small formula and print it so the check can see the result.
Practise Expressions and Operators
Reading is free and needs no account. Practice, mocks and progress live in the app.
- A 2-question practice set that ends the chapter
- 2 quick checks with worked explanations
- Timed mocks scored with the real marking scheme
- Readiness tracked per topic, kept on your device