Python Operators
Operators can be applied to variables and values. In Python, operators are keywords or special characters. The value on which
these operators work are called operands.
Operators you already know are the ones you learned in math class like addition ( + ) and substraction( ‐ ). But there are many
other operators.
Related course: Complete Python Programming Course & Exercises
Types of Python Operators
Python has these types of operators:
Arithmetic Operators
Logical Operators
Comparison Operators
Bitwise Operators
Assignment Operators
Membership Operators
Identity Operators
Arithmetic Operators
These operators can be applied to numbers. They are the typical ones you are already familiar with: addition (+), substraction
(-), multiplication (*) etc.
+ : addition operator
‐ : subtraction operator
* : multiplication operator
/ : division operator
** : exponential operator
// : oor division operator
The program below demonstrates the use of arithmetic operators:
, >>> x = 3
>>> y = 7
>>>
>>> sum = x + y
>>> print("x plus y is", sum)
x plus y is 10
>>>
>>> sub = x ‐ y
>>> print("x minus y is", sub)
x minus y is ‐4
>>>
>>> mult = x * y
>>> print("x times y is", mult)
x times y is 21
>>>
>>> divs = x / y
>>> print("division result ", divs)
division result 0.42857142857142855
>>>
>>> modulus = x % y
>>> print("modulus is", modulus)
modulus is 3
>>>
>>> exp = x ** 2
>>> print("exponent is", exp)
exponent is 9
>>>
>>> floor_division = x // y
>>> print("division is", floor_division)
division is 0
You can use the addition operator on strings too:
>>> print("hello " + "world")
hello world
Python Operators
Operators can be applied to variables and values. In Python, operators are keywords or special characters. The value on which
these operators work are called operands.
Operators you already know are the ones you learned in math class like addition ( + ) and substraction( ‐ ). But there are many
other operators.
Related course: Complete Python Programming Course & Exercises
Types of Python Operators
Python has these types of operators:
Arithmetic Operators
Logical Operators
Comparison Operators
Bitwise Operators
Assignment Operators
Membership Operators
Identity Operators
Arithmetic Operators
These operators can be applied to numbers. They are the typical ones you are already familiar with: addition (+), substraction
(-), multiplication (*) etc.
+ : addition operator
‐ : subtraction operator
* : multiplication operator
/ : division operator
** : exponential operator
// : oor division operator
The program below demonstrates the use of arithmetic operators:
, >>> x = 3
>>> y = 7
>>>
>>> sum = x + y
>>> print("x plus y is", sum)
x plus y is 10
>>>
>>> sub = x ‐ y
>>> print("x minus y is", sub)
x minus y is ‐4
>>>
>>> mult = x * y
>>> print("x times y is", mult)
x times y is 21
>>>
>>> divs = x / y
>>> print("division result ", divs)
division result 0.42857142857142855
>>>
>>> modulus = x % y
>>> print("modulus is", modulus)
modulus is 3
>>>
>>> exp = x ** 2
>>> print("exponent is", exp)
exponent is 9
>>>
>>> floor_division = x // y
>>> print("division is", floor_division)
division is 0
You can use the addition operator on strings too:
>>> print("hello " + "world")
hello world