SimpleTuts.com

Python Operators

Operators in Python are special symbols that perform operations on variables and values, including arithmetic, comparison, logical, assignment, bitwise, identity, and membership operations.

Arithmetic Operators

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder)
** Exponentiation
// Floor division

Comparison Operators

Operator Description
== Equal to
!= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to

Logical Operators

Operator Description
and Logical AND
or Logical OR
not Logical NOT

Assignment Operators

Operator Description
= Assigns a value to a variable
+= Adds and assigns
-= Subtracts and assigns
*= Multiplies and assigns
/= Divides and assigns
%= Modulus and assigns
**= Exponentiates and assigns
//= Floor divides and assigns

Identity Operators

Operator Description
is Returns true if both variables are the same object
is not Returns true if both variables are not the same object

Membership Operators

Operator Description
in Returns true if a sequence with the specified value is present in the object
not in Returns true if a sequence with the specified value is not present in the object

Bitwise Operators

Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise NOT
<< Bitwise left shift
>> Bitwise right shift
More about Bitwise Operators