Python Boolean Operator Flashcards

 

card 1 of 21

 

True+0

 

in some ways, True behaves like the integer 1

1

card 2 of 21

 

True*3

 

in some ways, True behaves like 1

3

card 3 of 21

 

5*False

 

in some ways, False behaves like zero

0

card 4 of 21

 

True+False

 

the + operator forces True/False to act as numbers

1

card 5 of 21

 

True and False

 

common sense

False

card 6 of 21

 

False or True

 

the "or" operator is logical (but maybe unfamiliar)

True

card 7 of 21

 

True and 'a'

 

this one is strange

'a'

card 8 of 21

 

is it a good idea to use +, *, numbers or strings with True/False?

 

let's keep things simple ...

No!

card 9 of 21

 

True or False and False

 

Python evaluates expressions left-to-right, except by precedence

True

card 10 of 21

 

(True or False) and False

 

first evaluate parenthesized expressions

False

card 11 of 21

 

not True

 

the "not" operator is somewhat like the minus sign (it is "unary")

False

card 12 of 21

 

not False

 

if it's not False, it must be ...

True

card 13 of 21

 

not not True

 

--3 is -(-3) is 3, evaluating left-to-right

True

card 14 of 21

 

not True or False

 

the "not" operator has priority over other operators in evaluation

False

card 15 of 21

 

False or not True

 

the "not" operator has priority over other operators in evaluation

False

card 16 of 21

 

not (True or False)

 

evaluate parenthesized expressions first

False

card 17 of 21

 

not 9

 

with some exceptions, values tend to behave like True

False

card 18 of 21

 

not 0

 

exceptions include 0, 0.0, and the empty string ''

True

card 19 of 21

 

not "not"

 

with some exceptions, values tend to behave like True

False

card 20 of 21

 

0.124 and "nonsense"

 

with some exceptions, values tend to behave like True -- here is an exception

'nonsense'

card 21 of 21

 

is it a good idea to mix the use of character strings and numbers with logical operators, "and", "or", "not" ?

 

let's keep things simple ...

No!

 

End of Problem Set

(use browser reload to restart this problem set)