EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Python 3 Operators

Secondary Sidebar
Python 3 Tutorial
  • Python 3 Tutorial
    • Python 3 Commands
    • Python 3 Array
    • Python 3 Operators
    • Python 3 NumPy
    • Python 3 Webserver
    • Python 3 yield
    • Python 3 Pip
    • Python 3 Install
    • Python 3 raw_input
    • Python 3 HTTP Server
    • Python 3 Threading
    • Python 3 Requests
    • Python 3 Module Index
    • Python 3 String Format
    • Python 3 Unicode
    • Python 3 GUI
    • Python 3 xrange
    • Python 3 Tuple
    • Python 3 input
    • Python 3 JSON
    • Python 3 string
    • Python 3 try-except
    • Python 3 RegEx
    • Python 3 Object-Oriented Programming
    • Python 3 zip
    • Python 3 Exception
    • Python 3 write to file
    • Python 3 Functions
    • Python 3 List Function
    • Python 3 While Loop
    • Python 3 Global Variable
    • Python 3 String Methods
    • Python 3 interpreter
    • Python 3 REPL
    • Python 3 else if
    • Python 3 basics
    • Python 3 cheat sheet
    • Python 3 Print
    • Python 3 For Loop
    • Python 3 range
    • Python 3 Dictionary
    • Python 3 has_key
    • Python 3 URLlib
Home Software Development Software Development Tutorials Python 3 Tutorial Python 3 Operators

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.

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Types of Python 3 Operators

Below are the types of python 3 operators:

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

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
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More