Product SiteDocumentation Site

4.5. Shorthand Operator

x op = expression is the syntax for shorthand operators. It will be evaluated like x = x op expression , Few examples are
 
>>> a = 12
>>> a += 13
>>> a
25
>>> a /= 3
>>> a
8
>>> a += (26* 32)
>>> a
840

shorthand.py example
 
#!/usr/bin/env python
N = 100
a = 2
while a < N:
    print "%d" % a
    a *= a

The output
 
$ ./shorthand.py
2
4
16