User manual

def changeGlobal():
global x # because of this statement…
x = 314 # ...this changes the global variable x
def changeLocal():
x = 42 # this statement does not change the global variable x
print x # will print 42 but the global variable x is unchanged
Creang globals on the fly
def newGlobal():
global x # this is a global variable, even without previous declaration
x = x + 1 # ERROR! - variables must be initialized before use
if x > 7: # ERROR! variables must be initialized before use
pass
# Note that these two statements are NOT errors if some other function
# has previously initialized a value for global variable x before this
# function runs. Globals declared in this way have the same availability
# as globals explicitly initialized outside the scope of any function.
The usual comparators are supported
Symbol Meaning
== Is equal to
!= Is not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
if 2 == 4:
print "something is wrong!"
if 1 != 1:
print "something is wrong!"
if 1 < 2:
print "that’s what I thought"
10 SNAP® Network Operang System