Symbol | Explanation |
---|---|
== |
The Same |
!= |
Not the Same |
> |
Greater Than |
>= |
Greater Than or Equal To |
< |
Less Than |
<= |
Less Than or Equal To ! |
True
or
False
if
statementsif ... else ...
statementif ... elif ... else
statementif ... else ...
statementsTrue
or False
True
else
is used as the ultimate result for
a test expression
False
is_equal(1) –> True
is_equal(“Hello”) –> False
elif
is a keyword in Python to replace the
else if
conditions from other languagesx
is equal to 1
x == 1
the check passes(True, "x is 1")
is returnedx
is equal to 1
x == 2
, the check fails, move onto the next
checky
is equal to 2
y == 2
, the check passes(True, "y is 2")
is returnedx
is equal to 1
x == 2
, the check fails, move onto the next
checky
is equal to 2
y == 3
, the check fails, move onto the next
check(False, "x is not 1 and y is not 2")
is
returnedif ... else
statements can be written
inside each other
x
is equal to 1
x == 1
, the check passes, move onto the
next checkif
statement is now actioned and
a second check is performed on whether y
is
equal to 2
y == 3
, the check fails, move onto the next
checky
is equal to 4
y == 3
, the check fails, move onto the next
check(False, "x is 1 and y is not 2 or 4")
is
returnedx
is equal to 1
x == 2
, the check fails, move onto the next
checkif
statement does not execute
and the final case is reached
("False", "x is not 1")
is returnedx
is equal to 1
x == 1
, the check passes, move onto the
next checkif
statement is now actioned and
a second check is performed on whether y
is
equal to 2
y == 2
, the check passes(True, "x is 1 and y is 2")
is
returnedx
is equal to 1
x == 1
, the check passes, move onto the
next checkif
statement is now actioned and
a second check is performed on whether y
is
equal to 2
y == 4
, the check fails, move onto the next
checky
is equal to 4
y == 4
, the check passes(True, "x is 1 and y is 4")
is
returnedx
is equal to 1
x == 1
, the check passes, move onto the
next checkif
statement is now actioned and
a second check is performed on whether y
is
equal to 2
y == 5
, the check fails, move onto the next
checky
is equal to 4
y == 5
, the check fails, move onto the next
check(False, "x is 1 but y is not 2 or 4")
is
returned