What are the operators in Python
Operators in Python
The following table lists the operators in Python and their meaning and precedence.
Operator | Description | Precedence |
---|---|---|
lambda | Lambda expression | 1 |
or | Logical or | 2 |
and | Logical and | 3 |
not | Logical negation | 4 |
in | Membership test | 5 |
not in | Negative membership test | 5 |
is | Identity test | 6 |
is not | Negative identity test | 6 |
< | Less than | 7 |
> | Greater than | 7 |
<= | Less than or equal to | 7 |
>= | Greater than or equal to | 7 |
== | Equal to | 7 |
!= | Not equal to | 7 |
| | Bitwise or | 8 |
^ | Bitwise exclusive or | 9 |
& | Bitwise and | 10 |
<< | Left shift | 11 |
>> | Right shift | 11 |
+ | Addition | 12 |
- | Subtraction | 12 |
* | Multiplication | 13 |
/ | Division | 13 |
% | Remainder | 13 |
+ | Unary identity | 14 |
- | Unary negation | 14 |
~ | Bitwise complement | 15 |
** | Exponentiation | 16 |
x.attribute | Attribute reference | 17 |
x[index] | Subscription | 18 |
x[index1:index2[:index3]] | Slicing | 19 |
f(args...) | Function call | 20 |
(...) | Parenthesized expression or tuple display | 21 |
[...] | List display | 22 |
{key:value, ...} | Dictionary display | 23 |
`expressions...` | String conversion | 24 |