Free Online Flashcard Deck

3 Conditional Control Flow Free Online FlashCards

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

12 cards
01
Front

What does a Python `if` statement do?

Back

An `if` statement executes its indented block only when its condition evaluates to true.

02
Front

What do the colon and indentation signify in an `if` block?

Back

The colon begins the controlled block, and indentation identifies the statements belonging to it. Python conventionally uses four spaces per indentation level.

03
Front

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

Back

Python tests `if` and `elif` conditions from top to bottom, executes the first true branch, and skips the remaining branches. `else` runs when none is true.

04
Front

Why should specific conditional tests come before broad tests?

Back

Put the more specific or restrictive test first. Otherwise, a broader true condition may run before Python reaches the specific case.

05
Front

What is the difference between `==` and `=` in Python?

Back

`==` compares values, while `=` assigns a value to a variable.

06
Front

When should Python use `is` instead of `==`?

Back

Use `is` for object identity checks such as `value is None`; use `==` when comparing values.

07
Front

What does `18 <= age < 65` mean?

Back

A chained comparison such as `18 <= age < 65` is equivalent to `18 <= age and age < 65`; the middle expression is evaluated once.

08
Front

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

Back

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

09
Front

How does short-circuit evaluation work?

Back

Python evaluates `and` and `or` left to right and stops when the result is already known. A false left side stops `and`; a true left side stops `or`.

10
Front

Which common Python values are false in conditionals?

Back

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

11
Front

What does a collection mean when used directly as a condition?

Back

Testing a collection directly checks whether it contains elements: an empty collection is false, while a nonempty collection is true.

12
Front

What is a nested conditional?

Back

Nesting places one conditional inside another. The inner condition is evaluated only when the outer condition succeeds, and its block must be indented farther.