Operators are used to perform operations on variables and values.
In the example below, we use the + operator to add together two values:
Example print(10 + 5) Run example »Python divides the operators in the following groups:
Arithmetic operators Assignment operators Comparison operators Logical operators Identity operators Membership operators Bitwise operators Python Arithmetic OperatorsArithmetic operators are used with numeric values to perform common mathematical operations:
Operator Name Example Try it + Addition x + y Try it » - Subtraction x - y Try it » * Multiplication x * y Try it » / Division x / y Try it » % Modulus x % y Try it » ** Exponentiation x ** y Try it » // Floor division x // y Try it » Python Assignment OperatorsAssignment operators are used to assign values to variables:
Operator Example Same As Try it = x = 5 x = 5 Try it » += x += 3 x = x + 3 Try it » -= x -= 3 x = x - 3 Try it » *= x *= 3 x = x * 3 Try it » /= x /= 3 x = x / 3 Try it » %= x %= 3 x = x % 3 Try it » //= x //= 3 x = x // 3 Try it » **= x **= 3 x = x ** 3 Try it » &= x &= 3 x = x & 3 Try it » |= x |= 3 x = x | 3 Try it » ^= x ^= 3 x = x ^ 3 Try it » >>= x >>= 3 x = x >> 3 Try it »