With d = {"a": 1, "b": 2}, what does 2 in d return?
Membership on a dict checks keys. Use 2 in d.values() to search values.
Operators and Expressions · Exercise 1 of 4
Fifteen multiple-choice questions on Python operators: division, modulo and power, precedence, chained comparisons, logical and bitwise operators, identity, membership and the walrus operator. Pick an option to check your answer instantly.
With d = {"a": 1, "b": 2}, what does 2 in d return?
Membership on a dict checks keys. Use 2 in d.values() to search values.
How do you add 1 to count in Python?
Python has no ++ or -- operators. count++ is a SyntaxError and ++count is just +(+count), which changes nothing.
What does the walrus operator := do?
It allows if (n := len(data)) > 10: … – computing len once and keeping the result. It was added in Python 3.8.
How does Python group not a or b and c?
Precedence is not > and > or: not applies to a, and binds b and c, then or joins the two parts.
If x = 4, what is x after x *= 2 + 3?
An augmented assignment evaluates the whole right-hand side first: x = 4 * (2 + 3) = 20.
Timed online tests with instant scores and explanations.