The following tables shows all the various operators you can use in Jython. HCSS and HIPE use Jython version 2.5.2.
This list and the associated operator descriptions have been largely
taken from the Python Reference Manual, which you can find online at http:
Table A.1. Jython unary arithmetic operators
Operator |
Operator description |
Example |
|
Unary plus: yields its numeric argument unchanged. |
print +5 #5
|
|
Unary minus: yields the negation of its numeric argument. |
print -5 #-5
|
|
Invert: yields the bitwise invert of its plain or long integer argument. |
print ~5 #-6
|
Table A.2. Jython binary arithmetic operators
Operator |
Operator description |
Example |
|
Sum: yields the sum of its arguments. |
print 2 + 2 # 4
|
|
Subtraction: yields the difference of its arguments. |
print 2 - 3 # -1
|
|
Multiplication: yields the product of is arguments. |
print 3 * 2 # 6
|
|
Division: yields the quotient of its arguments. |
print 5 / 2 # 2 print 5.0 / 2 # 2.5
|
|
Floor division
(Jython 2.2 alpha only): yields the result of the
|
print 5 // 2 # 2 print 5.0 // 2 # 2.0
|
|
Modulo: yields the remainder from the division of its arguments. |
print 5 % 2 # 1
|
|
Power: yields its left argument raised to the power of its right argument. |
print 5**2 # 25
|
Table A.3. Jython shifting operators
Operator |
Operator description |
Example |
|
Left
shift: |
print 5 << 1 # 10
|
|
Right
shift: |
print 5 >> 1 # 2
|
Table A.4. Jython binary bitwise operators
Operator |
Operator description |
Example |
|
Bitwise AND: yields the bitwise AND of its plain or long integer arguments. |
print 5 & 6 # 4
|
|
Bitwise XOR: yields the bitwise exclusive OR of its plain or long integer arguments. |
print 5 ^ 6 # 3
|
|
Bitwise OR: yields the bitwise inclusive OR of its plain or long integer arguments. |
print 5 | 6 # 7
|
Table A.5. Jython comparison operators
Operator |
Operator description |
Example |
|
Less
than: |
print 5 < 6 # 1
|
|
Greater
than: |
print 5 > 6 # 0
|
|
Equal
to: |
print 5 == 6 # 0
|
|
Greater or
equal to: |
print 5 >= 6 # 0
|
|
Less or equal
to: |
print 5 <= 6 # 1
|
|
Not equal
to: |
print 5 != 6 # 1 print 5 <> 5 # 0
|
Table A.6. Jython boolean operators
Operator |
Operator description |
Example |
|
Boolean
AND: yields |
|
|
Boolean
OR: yields |
|
|
Boolean
NOT: yields |
|