Following operators can be used in a loop or to check conditions in a if…else… statement:

1
2
3
4
5
6
7
8
9
10
Check Boolean
not False

Check Int/String
< 	less than
<= 	less than or equal to
> 	greater than
>= 	greater than or equal to
== 	equal
!= 	not equal

if…elif…else… statement

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/python
# check if var is set/true
var = True

if not var:
  print "I'm false"
elif var:
  print "I'm true"

# Check if integer smaller than x
x = 1

if x <= 1:
  print "smaller or equal 1"
elif x <= 10:
  print "smaller or equal 10"
else:
  print "bigger than 10"

# Check if variable test is set

#test = "Hello World"

try: test
except NameError: test = None

if test is None:
  print "Variable test is not set"
else:
  print test  

While loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/python
# easy loop do while var is False
var = False
while (var == False):
    print "var is false"
    var = True

# More complex loop print message "var is False" 10 times before break out of while"
var = False
i = 0
while (var == False):
    while ( i <= 10 ):
        i = i + 1
        print "var is False"
    #var = True  
    break