Flow control Flashcards
(43 cards)
What is “Flow control”
Flow control statements can decide which Python instructions to execute under which conditions.
What is the Boolean Value?
True or False and they always start with a capital T and F
When do you get error while using boolean values?
➊. If you don’t use the proper case
➋ or you try to use True and False for variable names
what do comparison operators do?
compare two values and evaluate down to a single Boolean value.
What is the other name of comparison operators?
relational operators,
What is the comparison operators for
“Equal to”
==
What is the comparison operators for
Not equal to
!=
What is the comparison operators for
Less than
What is the comparison operators for
Greater than
>
What is the comparison operators for
Less than or equal to
<=
What is the comparison operators for
Greater than or equal to
> =
What is the output of 42 == ‘42’ ? Why?
False, because and int or float are not equal to string
what is the output of 42 == 42.0?
True
what is the name and difference of == and =
The == operator (equal to) asks whether two values are the same as each other.
The = operator (assignment) puts the value on the right into the variable on the left.
What are the Boolean Operators?
and
or
no
Why are the and and or binary operators?
The and and or operators always take two Boolean values (or expressions), so they’re considered binary operators.
The and and or Operator’s Truth Table: True and True ? True and False ? False and True ? False and False ? True or True ? True or False ? False or True ? False or False ?
True False False False True True True False
Why is not operator a unary operator
Unlike and and or, the not operator operates on only one Boolean value (or expression). This makes it a unary operator
The not Operator’s Truth Table:
Expression Evaluates to . . .
not True ?
not False ?
False
True
Example of Mixing Boolean and Comparison Operators
> > > (4 < 5) and (5 < 6)
True
2 + 2 == 4 and not 2 + 2 == 5 and 2 * 2 == 2 + 2
True
what is the order of operations for the Boolean operators
math comparison operators not and or
What are the Elements of Flow Control?
condition and block of code (clause)
What is a block of code?
Blocks begin when the indentation increases.
Blocks can contain other blocks.
Blocks end when the indentation decreases to zero or to a containing block’s indentation.
Example of an if statement? Explain the component
if name == ‘Alice’:
print(‘Hi, Alice.’)
1. The if keyword
2. A condition (that is, an expression that evaluates to True or False)
3. A colon
4. Starting on the next line, an indented block of code (called the if clause)