Free Online Flashcard Deck

3 Control Flow Free Online FlashCards

Study 3 Control Flow with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

How does Python identify code blocks?

Back

Python uses indentation to identify which statements belong to an `if`, `while`, or `for` block. Statements in the same block must be indented consistently.

02
Front

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

Back

`and` is true when both operands are true; `or` is true when at least one operand is true; `not` reverses a truth value.

03
Front

What is short-circuit evaluation?

Back

Short-circuit evaluation stops `and` when its left operand is false and stops `or` when its left operand is true, so unnecessary or unsafe expressions may not run.

04
Front

Which common Python values are falsy?

Back

Falsy values include `False`, `None`, numeric zero, and empty strings or collections. Most other objects are truthy.

05
Front

When should Python use `==` rather than `is`?

Back

Use `==` to compare values. Use `is` mainly for object identity checks involving singletons such as `None`.

06
Front

What does `0 <= score <= 100` mean?

Back

A chained comparison such as `0 <= score <= 100` expresses both comparisons and evaluates the middle expression only once.

07
Front

How does Python choose among `if` and `elif` branches?

Back

Python tests `if` and `elif` conditions from top to bottom and executes only the first matching branch. Remaining branches are skipped.

08
Front

When does a `while` loop execute its body?

Back

A `while` loop checks its condition before every iteration. If the condition is initially false, its body runs zero times.

09
Front

When is a `while` loop appropriate?

Back

Use a `while` loop when repetition depends on a condition that changes during execution or when the number of repetitions is not known in advance.

10
Front

How does a Python `for` loop traverse data?

Back

A `for` loop assigns each item from an iterable to a loop variable and runs its body. It ends when the iterable is exhausted.

11
Front

How can a `for` loop obtain both index and item?

Back

`enumerate()` supplies both an index and an item, as in `for index, name in enumerate(names):`.

12
Front

Is the stop value included in `range()`?

Back

The `stop` value in `range()` is exclusive. For example, `range(5)` produces the integers 0 through 4.