Free Online Flashcard Deck

04. Conditional Statements Free Online FlashCards

Study 04. Conditional Statements with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What does a conditional statement control?

Back

A conditional statement controls which instructions execute by evaluating a condition as true or false and selecting an appropriate branch.

02
Front

What syntax defines an `if` block in Python?

Back

Python uses a colon after the condition and indentation to define the statements controlled by an `if` statement.

03
Front

How does an `if-else` statement choose a branch?

Back

An `if-else` statement chooses between two alternatives: the `if` branch runs when its condition is true; otherwise, the `else` branch runs.

04
Front

What happens in an `elif` chain?

Back

Python tests `elif` conditions from top to bottom and executes only the first branch whose condition is true.

05
Front

How should chained conditions be ordered?

Back

Put more specific or higher-priority conditions before broader ones; otherwise, the broad branch may match first and make later branches unreachable.

06
Front

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

Back

Use `==` to compare values. A single `=` assigns a value to a variable rather than testing equality.

07
Front

When is an `and` expression true?

Back

`and` is true only when both of its conditions are true.

08
Front

What do `or` and `not` do?

Back

`or` is true when at least one condition is true, while `not` reverses a Boolean result.

09
Front

Which Python values are generally false in conditions?

Back

Values such as `0`, `None`, and empty collections are generally treated as false in Python conditions.

10
Front

When is a nested condition evaluated?

Back

A nested condition is an `if` statement inside another conditional block; the inner condition is evaluated only after the outer condition succeeds.

11
Front

What is the purpose of validation?

Back

Validation checks input form and allowed range before use, reports failures, and continues only when the input is valid.

12
Front

What is a guard clause?

Back

A guard clause handles an invalid or exceptional case immediately, often with `return`, so the main operation needs less nesting.