Control Structures Flashcards
Boolean
Binary variable, True or False
==
Creates boolean variable
ex: print(2==3) –> False
!=
Not equal operator
ex: print(1 != 1) –> False
> ,<
Determine if one float/integer is greater than or less than the other
ex: print(7 > 5) –>
True
print(10 < 10) –>
False
> =,<=
Determine if one float/integer is greater or equal to than or less than or equal to the other
ex: print(7 >= 5) –>
True
print(10 <= 10) –>
True
Lexicographically
How strings are compared, a=1 e=5, etc.
ex: print(“Annie” > “Andy”) –> True
if
Runs code if a certain condition holds True. Statement within are indented
ex: if 10 > 5:
print(“10 greater than 5”)
Can if statements be nested?
True
ex: num = 12
if num > 5:
print(“Bigger than 5”)
if num <=47:
print(“Between 5 and 47”) –>
Bigger than 5
Between 5 and 47
else
Runs code when the if statement is False
ex:
x = 4
if x == 5:
print(“Yes”)
else:
print(“No”)
elif
else if, used to chain else if statements
ex:
if num == 1:
print(“One”)
elif num == 2:
print(“Two”)
else:
print(“Something else”)
and
Evaluates True only if both statements are true
ex: print(1 == 1 and 2 == 2) –> True
print(1 == 1 and 2 == 3) –> False
or
Evaluates True if one or both statements are true, only evaluated False if both statements are false
ex:print(1 == 1 or 2 == 2) –> True
print(1 == 1 or 2 == 3) –> True
Not
Inverts argument
ex: print(not 1==1) –> False
== comes before and/or in order of operations
True
[]
Creates list
ex: words = [“Hello” , “World” , “!”]