EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Python 3 Tutorial Python 3 Operators
 

Python 3 Operators

Updated February 20, 2023

Python 3 Operators

 

 

Introduction to Python 3 Operators

Python 3 operators are used to manipulate values and variables. In general, there are multiple types of operators available in python. Therefore, operators are very useful and important in python. Types of operators are divided into their operations, performed on the operand. There are six types of operators available in python. The arithmetic operator is mostly used in python to solve arithmetic operations.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

What are Python 3 Operators?

The operator module provides a set of high-performance functions that correspond to python’s intrinsic operators. The expression py1+py2 is equal to the operator.add (py1, py2). Without the two underscores, names of functions are utilized for specific methods. Many of them have a variation with double underscores preserved for backward compatibility. For clarity’s sake, variations without double underscores are recommended. Mathematical operations and sequence operations are among the categories of functions available.

Types of Python 3 Operators

Below are the types of python 3 operators:

Python 3 operator is divided into multiple types.

1. Arithmetic Operator

An arithmetic operator is used to perform arithmetic operations. There is multiple arithmetic operator available in python. Below is the example of the arithmetic operator as follows. In the below example, we perform multiplication, addition, subtraction, and division operation as follows.

In the below example, we have used two variables, py1 and py2, to declare the value on which we have performed the arithmetic operation.

Code:

py1 = 20
py2 = 5
addition = py1 + py2
subtraction = py1 - py2
multiplication = py1 * py2
division = py1 / py2
print (addition)
print (subtraction)
print (multiplication)
print (division)

Output:

Python 3 Operators 1

2. Comparison Operator

A comparison operator is used to compare the values on the condition to either return true or false. Below is the example of a comparison operator as follows. In the example below, we perform greater than, less than, not equal to, and equal to operation.

In the below example, we have used two variables, py1 and py2, to declare the value on which we have performed a comparison operation.

Code:

py1 = 25
py2 = 35
print (py1 > py2)
print (py1 < py2)
print (py1 == py2)
print (py1 != py2)

Output:

Python 3 Operators 2

3. Logical Operator

Below is the example of a logical operator as follows. In the below example, we are performing and, not and or operation as follows.

In the below example, we have used two variables, py1 and py2, to declare the value on which we have performed a logical operation.

Code:

py1 = True
py2 = False
print (py1 and py2)
print (py1 or py2)
print (not py1)

Output:

Python 3 Operators 3

4. Bitwise Operator

Below is the example of the bitwise operator as follows. In the below example, we are performing bitwise or not, and xor operations are as follows. In the below example, we have used two variables, py1 and py2, to declare the value on which we have performed the bitwise operation.

Code:

py1 = 25
py2 = 15
print (py1 & py2)
print (py1 | py2)
print (~py1)
print (py1 ^ py2)

Output:

Python 3 Operators 4

5. Assignment Operator

Below is the example of assignment operators as follows. In the below example, we have performing =, +=, -=, and *= operations.

Code:

py1 = 15
py2 = py1
print (py2)
py2 += py1
print (py2)
py2 -= py1
print (py2)
py2 *= py1
print (py1)

Output:

Python 3 Operators 5

6. Identity Operator

Below is the example of an identity operator as follows. In the below example, we are performing and are not operating as follows.

Code:

py1 = 15
py2 = 25
py3 = py1
print (py1 is not py2)
print (py1 is py3)

Output:

Python 3 Operators 6

7. Membership Operator

Below is the example of a membership operator as follows. In the below example, we are performing in and not in operation.

Code:

py1 = 15
py2 = 43
py_list = [27, 19, 43, 67, 84]
if (py1 not in py_list):
print ("py1 not present")
if (py2 in py_list):
print ("py2 present")

Output:

Python 3 Operators 7

Python 3 Operators Arithmetic

Below is the arithmetic operator available in python:

1. Addition

This operator is used to add two numbers.

The below example shows the addition operator.

Code:

py1 = 15
py2 = 43
print (py1+py2)

Output:

Python 3 Operators 8

2. Subtraction

This operator is used to subtract two numbers.

The below example shows the subtraction operator.

Code:

py1 = 15
py2 = 43
print (py1-py2)

Output:

Subtraction

3. Division

This operator is used to divide two numbers.

The below example shows the division operator.

Code:

py1 = 25
py2 = 5
print (py1/py2)

Output:

Division

4. Multiplication

This operator is used to multiply two numbers.

The below example shows the multiplication operator.

Code:

py1 = 25
py2 = 5
print (py1*py2)

Output:

Multiplication

5. Modulus

This operator is used to return the remainder.

The below example shows the modulus operator.

Code:

py1 = 37
py2 = 5
print (py1%py2)

Output:

Modulus

Python 3 Operators Comparison

Below is the comparison operator available in python as follows:

  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)
  • Equal to (==)
  • Not equal to (!=)

Below example shows the python 3 comparison operator as follows:

Code:

py1 = 19
py2 = 39
print(py1 > py2)
print(py1 < py2)
print(py1 == py2)
print(py1 != py2)
print(py1 >= py2)
print(py1 <= py2)

Output:

Comparison

Python 3 Operators Values

While using any operator in python, we need first assign a value to the variable; after assigning the value, we are doing the operation.

In the below example, we are declaring two-variable names as py_val1 and py_val2 as follows.

Code:

py_val1 = 15
py_val2 = 43
print (py_val1+py_val2)
print (py_val1-py_val2)
print (py_val1*py_val2)
print (py_val1/py_val2)

Output:

Values

Conclusion

The operator module provides a set of high-performance functions that correspond to python’s intrinsic operators. For example, python 3 operators are used to manipulate values and variables. There are multiple types of operators available in python. Types of operators are divided into their operations, which they perform on the operand.

Recommended Articles

This is a guide to Python 3 Operators. Here we discuss the introduction, types of Python 3 operators, comparison, and values, respectively. You may also have a look at the following articles to learn more –

  1. Python User-Defined Exception
  2. Python Reduce
  3. Timsort Python
  4. Python Z Test
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW