Python Operators

₹50

₹60

Instructor: kLanguage: english

About the course

 

Python Operators

Python Operators in general are used to perform operations on values and variabls. These are standard symbols used for the purpose of logical and arithmetic operations. In this article, we will look into different types of Python operators. 

 

  • OPERATORS: Are the special symbols. Eg- + , * , /, etc.
  • Arithmetic Operators

    Arithmetic operators are used to performing mathematical operations like addition, subtraction, multiplication, and division.

    Operator

    Description

    Syntax

    +

    Addition: adds two operands

    x + y

    -

    Subtraction: subtracts two operands

    x - y

    *

    Multiplication: multiplies two operands

    x * y

    /

    Division (float): divides the first operand by the second

    x / y

  •  

//

Division (floor): divides the first operand by the second

x // y

%

Modulus: returns the remainder when the first operand is divided by the second

x % y

**

Power: Returns first raised to power second

PRECEDENCE:

  • P - Parentheses
  • E - Exponentiation
  • M - Multiplication     (Multiplication and division have the same precedence)
  • D - Division
  • A - Addition     (Addition and subtraction have the same precedence)
  • S - Subtraction

The modulus operator helps us extract the last digit/s of a number. For example:

  • x % 10 -> yields the last digit
  • x % 100 -> yield last two digits

Example: Arithmetic operators in Python

Python3

# Examples of Arithmetic Operator

x ** y

a = 9

b = 4

# Addition of numbers

add = a + b

# Subtraction of numbers

sub = a - b

# Multiplication of number

mul = a * b

# Division(float) of number

div1 = a / b

# Division(floor) of number

div2 = a // b

# Modulo of both number

mod = a % b

# Power

p = a ** b

# print results

print(add)

print(sub)

print(mul)

print(div1)

print(div2)

print(mod)

print(p)

Output

 

13

5

36

2.25

2

1

6561

Note: Refer to Differences between / and // for some interesting facts about these two operators.

Syllabus

Meet k

telugu&english language,e, all government exams prepared assiperents

What do we offer

Live learning

Learn live with top educators, chat with teachers and other attendees, and get your doubts cleared.

Structured learning

Our curriculum is designed by experts to make sure you get the best learning experience.

Community & Networking

Interact and network with like-minded folks from various backgrounds in exclusive chat groups.

Learn with the best

Stuck on something? Discuss it with your peers and the instructors in the inbuilt chat groups.

Practice tests

With the quizzes and live tests practice what you learned, and track your class performance.

Get certified

Flaunt your skills with course certificates. You can showcase the certificates on LinkedIn with a click.

Reviews and Testimonials