Python Chapter 4: Decisions & Conditionals

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/26

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards defining fundamental concepts of Python Chapter 4, including Boolean logic, comparison and logical operators, branching structures (if, elif, else), nested and chained decisions, operator precedence, conditional expressions, and standard runtime/syntax errors.

27 Terms

1
New cards

Condition

An expression that evaluates to either true or false (truthy or falsy) to determine the flow of program execution.

2
New cards

Branch

A specific path or block of code selected for execution based on the evaluation of a conditional test.

3
New cards

Boolean (bool)

A built-in Python data type containing precisely two values: True and False (both capitalized).

4
New cards

Truthy

A property of any value that evaluates to True in a conditional statement, including nonzero numbers, nonempty strings, and nonempty collections.

5
New cards

Falsy

A property of any value that evaluates to False in a conditional statement, such as numeric zero (00, 0.00.0), empty strings (""), empty collections ([], {}), None, and False.

6
New cards

Equality Operator (==)

A comparison operator that checks whether the values or contents of two operands are equal.

7
New cards

Assignment Operator (=)

An operator used to assign and store a value into a variable, distinct from the equality comparison operator ==.

8
New cards

Identity Operator (is)

An operator that tests whether two references point to the exact same object in memory, rather than merely having equal values.

9
New cards

if Statement

A control flow statement that executes its indented code block only when its condition evaluates to a truthy value.

10
New cards

else Statement

An optional clause paired with an if statement at the same indentation level that executes its indented body only when the preceding condition evaluates to a falsy value.

11
New cards

elif Statement

A keyword standing for 'else if' that specifies an alternative condition to test only if all preceding branches in the decision chain evaluated to false.

12
New cards

Logical and Operator

A Boolean operator that evaluates to True only when both operands or conditions are true.

13
New cards

Logical or Operator

A Boolean operator that evaluates to True if at least one of its operands or conditions is true.

14
New cards

Logical not Operator

A unary Boolean operator that inverts or reverses the truth value of its operand.

15
New cards

Short-circuit Evaluation

The evaluation strategy where Python stops checking remaining operands in a logical expression as soon as the final result is determined (e.g., if the left side of and is false, or the left side of or is true).

16
New cards

Operator Precedence

The formal rules determining the order in which different operators are grouped and evaluated in an expression.

17
New cards

Associativity

The directional order (such as left-to-right for multiplication and division, or right-to-left for exponentiation) in which operators with equal precedence are grouped and evaluated.

18
New cards

Chained Decision

A multi-way decision structure using if/elif/else that evaluates conditions sequentially from top to bottom and executes at most the first matching branch.

19
New cards

Nested Decision

A decision structure placed inside the indented body of another if or else statement, requiring an additional level of indentation.

20
New cards

Chained Comparison

A concise Python comparison format (such as 13≤age<1813 \le \text{age} < 18) that tests multiple relational boundary conditions simultaneously without an explicit and operator.

21
New cards

Conditional Expression

A single-line ternary construct with the syntax value_if_true if condition else value_if_false used to select a value based on a condition.

22
New cards

Modulo Operator (%)

An arithmetic operator that returns the integer remainder of a division, frequently used to check divisibility or whether a number is even (number%2==0\text{number} \% 2 == 0).

23
New cards

pass Statement

A null statement in Python used as a temporary placeholder inside an empty code block to avoid indentation or syntax errors during development.

24
New cards

SyntaxError: expected ':'

A syntax error produced when an if, elif, or else header line is missing its required trailing colon (:).

25
New cards

IndentationError

An error raised when a code block has inconsistent spacing or fails to indent lines underneath a header (conventionally four spaces).

26
New cards

TypeError (Relational Comparison)

An error triggered in Python 3 when attempting to compare incompatible data types (such as a string and an integer) using relational operators like < or >.

27
New cards

ValueError (int conversion)

An error that occurs when int() is called on an input string containing nonnumeric characters that cannot be parsed as an integer.