Free Online Flashcard Deck

03. Expressions and Boolean Logic Free Online FlashCards

Study 03. Expressions and Boolean Logic with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is an expression in Python?

Back

An expression is code evaluated to produce a value; it may contain literals, variables, operators, and function calls.

02
Front

In `a + b`, what are the operator and operands?

Back

The operator performs the operation, while the operands are the values on which it operates. In `a + b`, `+` is the operator and `a` and `b` are operands.

03
Front

What is the result of `7 // 2`?

Back

`7 // 2` evaluates to `3` because floor division returns the floor of the quotient.

04
Front

What does `7 % 2` evaluate to?

Back

`7 % 2` evaluates to `1`; the `%` operator returns the remainder after division.

05
Front

How do `=` and `==` differ in Python?

Back

`=` assigns a value, while `==` tests whether two values are equal. For example, `x = 10` assigns; `x == 10` compares.

06
Front

What does `10 <= score <= 20` mean?

Back

The chained comparison is equivalent to `10 <= score and score <= 20`. It checks that `score` lies from 10 through 20, inclusive.

07
Front

What do Python's `not`, `and`, and `or` operators do?

Back

`not` reverses a truth value, `and` is true when both conditions are true, and `or` is true when at least one condition is true.

08
Front

Which common Python values are false in a Boolean context?

Back

`False`, `None`, numeric zero, and empty strings and containers are false in Boolean contexts; most other values are true.

09
Front

When do `and` and `or` short-circuit?

Back

`A and B` stops when `A` is false, while `A or B` stops when `A` is true, because the final result is already determined.

10
Front

What can Python's `and` and `or` return?

Back

Python's `and` and `or` return one of their operands, not necessarily `True` or `False`. Thus, `entered_name or "Guest"` produces `"Guest"` when `entered_name` is empty.

11
Front

How does `+` combine strings in Python?

Back

The `+` operator concatenates strings, and both operands must be strings. Convert other types with `str()` or use a formatted string.

12
Front

What is the result of `"-" * 5`?

Back

`"-" * 5` evaluates to `"-----"`; multiplying a string repeats it the specified number of times.