sweigart chapter 2 Flashcards
flow control statement
can decide which Phyton instructions to execute under which conditions. they directly correspond to the symbols in a flowchart.
Boolean values
comparison operators (relational operators)
compare two values and evaluate down to a single Boolean value.
and operator
evaluates an expression to True if both Boolean values are True.
or operator
evaluates an expression to True if either of the two Boolean values is True. if both are False, it evaluates to False.
not operator
operates on only one Boolean value (or expression).
condition
the same thing as an expression, but a more specific name in the context of flow control statements.
blocks
phyton code can be grouped together in blocks. one can tell where a block begins and ends from the identation of the lines of code.
clause
a block of code usually following a condition in flow control statements.
program execution
a term for the current instruction being executed.
if statement
the most common type of flow control statement. the block follow the if statement is the clause. if the statement condition is True the if statement’s clause will execute. the clause will be skipped if the condition is False.
elif statement
an ‘else if’ statement that always follows an if or another elif statement. it provides another condition that is checked only if all of the previous conditions were False.
while statement/while loop/loop
the code in a while clause will be executed as long as the while statement’s condition is True. the program execution jumps back to the start of the while statement at the end of the while clause. the condition is always checked at the start of each iteration.
break statement
a shortcut to getting the program execution to break out of a while loop’s clause early. if the execution reaches a break statement, it immediately exits the while loop’s clause.
continue statement
when the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop and re-evaluates the loop’s condition.