making a decision to take one path or another.
Simple Condition: only one condition
Compound Condition: the combination of two or more conditions
● Logical Operator
◎ " not " Logical Operator
not True = False
not False = True
◎ " and " Logical Operator
True and True = True
True and False = False
False and True = False
False and False = False
Note: " and " can connect as much as conditions we need,
but as long as there's one False condition,
the compound condition is False
◎ " or " Logical Operator
True or True = True
True or False = True
False or True = True
False or False = False
Note: " or " can connect as much as conditions we need,
but as long as there's one True condition,
the compound condition is True
● Using " in " Operator
Uses in conditon statements
print "e" in "this is a test message"
print "ess" in "this is a test message"
● If, elif and else
if <condition> :
elif <condition> :
elif <condition> :
Each consecutive lines of code is called a " BLOCK ".
Only one block will be executed.
If there's more then one condition is TRUE,
the block of the first true condition will be executed.
● while Loop
while <condition> :
Note: While the condition is TRUE, the code will be executed repeatedly
● Comparison Operators
== equal to
!= not equal to
> greater then
< less then
>= greater then or equal to
<= less then or equal to
● International Infinite Loop, break and continue
count = 0
count += 1
# end loop if count is greater then 7.
if count > 7:
# skip 2
if count == 2:
The condition is always true, so this is a international infinite loop.
When the code hits " continue ", the loop skip the rest of the codes
and starts from the first line of the block.
When the code hits " break ", the loop ended.
● for Loop
for < i > in <main squence> :
Note: A for loop repeats its loop body
for each element of the sequesce.
In this case, < i > is the varible
that represents the elements in the sequence
and <main squence> is the sequence.