R12.1 JA-2025July15
If Conditions
General Condition Structures
The general Python syntax for a simple if statement is as follows:
if condition:
Indented code blocks
If the condition is true, then the indented code blocks are implemented; if not, then the indented code blocks will be skipped.
The result of an if condition is a boolean type of value, and its legal value is either True or False. Bool is short for boolean in Python.
Comparison Symbols
The simplest condition is to compare two variables. The following table lists the comparison symbols of all the usual arithmetic.
Text | Math Symbols | Python Symbols |
Less than | < | < |
Greater than | > | > |
Less than or equal to | <= | <= |
Greater than or equal to | >= | >= |
Equals | = | == |
Not equal | != | != |
For example:
$var1 > 90
$var1 > $var2
($var1 - $var2)/($var3-$var4) > 1
And you can use and or or operators to combine two simple conditions. For example:
$var1 <90 and $var1>80
$var3 == 1 or $var4 == 1
![]() |
Tip: All the system built-in variables can be compared with None. For example:
|
![]() |
Note: A single equal sign (=) is not used to check for equality in Python. Use the double equal sign (==) instead. |