Operators and precedence
Arithmetic operators (floor division, modulo, power), comparison and logical operators, the order in which an expression is evaluated (precedence, associativity) and the short-circuit evaluation of logical operators.
- 27 cards
- 9 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- Scenarios
- Understand
- Line by line
- Step by step
- Cell by cell
A few cards from the deck
Operator precedence: what is it?
Show the answer
The rule that says which operator is applied first when an expression mixes several without parentheses.
2 + 3 * 4is 14:*goes before+. Parentheses always win:(2 + 3) * 4is 20.What does this statement print?
```python
print(2 3 2)`512643612
Show the answer
512**is right-associative:3 ** 2is computed first (9), then2 ** 9gives 512. Going left to right,(2 ** 3) ** 2, would give 64.In
a + 2,aand2are the … of the+operator. A … operator takes a single operand, likenotor the minus of-x; a binary operator takes two.Show the answer
In
a + 2,aand2are the operands of the+operator. A unary operator takes a single operand, likenotor the minus of-x; a binary operator takes two.The same sign can play both parts:
-is binary ina - band unary in-b.