Operators in expressions and their precedence


Operator

Value
Precedence
Comment
()
Grouping parts of expression
1 (Utmost)

!
Logic operation NOT
2

~
Bitwise inversion (NOT)
3

+
Single plus
4

-
Single minus
4

*
Multiplication
5

/
Division
5
Note, when dividing by zero
%
Modulus operator
5
you get error number.zerodivision.
\
Integer division
5
Operands are converted into Int.
+
Addition
6

-
Subtraction
6

<<
Bitwise left shift
7
Operands of all
>>
Bitwise right shift
7
bitwise operators
&
Bitwise operation AND
8
are implicitly
|
Bitwise operation OR
9
converted
!|
Bitwise operation XOR
10
into Int.
is
Check type
11

def
Is object defined?
11

in
Is the current document in directory?
11

-f
Does file exist?
11

d
Does directory exist?
11

==
Equal
12

!=
Not equal
12

eq
Strings are equal
12

ne
Strings are not equal
12

<
Number less than
13

>
Number greater than
13

<=
Number less than or equal
13

>=
Number greater than or equal
13

lt
String is less than
13

gt
String is greater than
13

le
String is less than or equal
13

ge
String is greater than or equal
13

&&
Logical operation AND
14
second operand is not evaluated if first is FALSE
||
Logical operation OR
15
second operand is not evaluated if first is TRUE
!||
Logical operation XOR
16 (Lowest)




Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 31.01.2017