If Statements Flashcards
what is the purpose of an if statement?
allows a program to carry out different actions depending on the nature of the data to be processed
what are compound statements?
spans multiple lies and consists of a header and a statement block and requires a colon (ex if statement)
what is a statement block?
group of one or more statements all indented to the same coloumn
how are if statements read?
instruction are executed if true or skipped if the condition is false`
what are relational operations? how are they read?
comparing two values usually used in if statements
what is the difference between assignment and equality testing?
assignments makes something true while equality testing checks if something is true
floor = 13 vs if floor == 13
what is lexicographical order?
coming strings in ‘dictionary’ like order
- all uppercase letters comes before lowercase
‘space’ comes before all other 2. printable character - digits come before all letters
what elif statements?
else if
–> as soon as one of the test conditions succeeds the statement block is executed
–> if none of the test conditions succeed the final else clause is executed
what is a boolean variable
often called a flag because it can either be up (true) or down (false)
what are the two boolean operators?
and, or
–> used to combine multiples conditions
what happens the operator “and” is used?
BOTH SIDES OF AND MOST BE TRUE FOR THE RESULT TO BE TRUE
What happens if the operator “or” is used?
either or both conditions must be true
how is the boolean operator “not” used?
to invert the comparison
or
checking inequality (substitute !=)
what is short circuit evaluations?
boolean operator “and”
–> evaluate conditions from left to right, if one is false then no need to continue
boolean operator “or”
–> if the left half of the “or “is true no need keep looking
What is the “in” operator?
used to analyze strings
–> see if a substring is inside of the string