Name |
Syntax example |
Comments |
|---|---|---|
Multiplication |
|
|
Division |
|
|
Remainder |
|
Often called mod or modulus |
Addition |
|
|
Subtraction |
|
|
Exponent |
|
Do not confuse this with Bitwise Xor ^ |
Bitshift Right |
|
|
Bitshift Left |
|
|
Bitwise And |
|
|
Bitwise Or |
|
|
Bitwise Xor |
|
The mathematical operators can also be used in the syntax a <operator>= b, for example, a += b.
This is merely a shortcut for a = a <operator> b, or in our example a = a + b.
Name |
Syntax Example |
Comments |
|---|---|---|
Less Than |
|
|
Greater Than |
|
|
Less Than or Equal To |
|
|
Greater Than or Equal To |
|
|
Equality |
|
|
Inequality |
|
|
Logical And |
|
Only use when |
Logical Or |
|
Only use when |
Logical Not |
|
Only use when |
Name |
Syntax Example |
Comments |
|---|---|---|
Typecast |
|
|
Typecast |
|
|
Type Equality/Compatibility |
|
|
Type Retrieval |
|
|
Type Retrieval |
|
Name |
Syntax Example |
Comments |
|---|---|---|
Member |
|
Classes are described in Part 08 - Classes |
Function Call |
|
Functions are described in Part 07 - Functions |
Post Increment |
|
|
Post Decrement |
|
|
Constructor Call |
|
Classes are described in Part 08 - Classes |
Name |
Syntax Example |
Comments |
|---|---|---|
Negative Value |
|
|
Pre Increment |
|
|
Pre Decrement |
|
|
Grouping |
|
When writing inline code, Pre Increment/Decrement (+i/-i) commit the action, then return its new value, whereas Post Increment/Decrement (i+/i-) return the current value, then commit the change.
num = 0
for i in range(5):
print num++
print '---'
num = 0
for i in range(5):
print ++num
|
0 1 2 3 4 --- 1 2 3 4 5 |
|
To make your code more readable, avoid using the incrementors and decrementors. |
Go on to Part 07 - Functions