Python Operators

Operators are used to perform operations on variables and values.

I. Python Arithmetic operators

OperationDescription
x + yAddition
x - ySubtraction
x * yMultipication
x / yDivision -> result is float
x // yDivision -> result is int
x % yRemainder of x / y for positive x, y
x ** yx to the power y

II. Python Comparison operators

They can be created by comparing values by using the rational operators

  • Equal: ==.
  • Not equal: !=
  • Greater than: >
  • Less than: <
  • Greater than or equal to: >=
  • Less than or equal to: <=

III. Python Logical operation

  • and
  • or
  • not

IV. Python Membership Operators

We can use membership operators to test if a sequence is presented in an object:

  • in
  • not in For example
>>> x = 2
>>> y = [2,4]
>>> x in y
True