Appendix A. Jython operators

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: / / docs.python.org/ reference/ .

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 floor() function applied to the quotient of its arguments.

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: a << b shifts plain or long integer a by b bits.

print 5 << 1
# 10

>>

Right shift: a >> b shifts plain or long integer a by b bits.

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: a < b yields true if a is less than b.

print 5 < 6
# 1

>

Greater than: a > b yields true if a is greater than b.

print 5 > 6
# 0

==

Equal to: a == b yields true if a and b are equal.

print 5 == 6
# 0

>=

Greater or equal to: a >= b yields true if a is greater than or equal to b.

print 5 >= 6
# 0

<=

Less or equal to: a <= b yields true if a is less than or equal to b.

print 5 <= 6
# 1

!= (preferred) or <>

Not equal to: a != b yields true if a is not equal to b.

print 5 != 6
# 1
print 5 <> 5
# 0


Table A.6. Jython boolean operators

Operator

Operator description

Example

and

Boolean AND: yields True if both arguments are true, False otherwise.

print 1 and 0
# 0

Example A.1. Boolean and operation between integers is also valid.


or

Boolean OR: yields True if at least one argument is true, False otherwise.

print 1 or 0
# 1

Example A.2. Boolean or operation between integers is also valid.


not

Boolean NOT: yields True if the argument is false, False otherwise.

print not 1
# 0

Example A.3. Boolean not operation between integers is also valid.