There are no items in your cart
Add More
Add More
Item Details | Price |
---|
Instructor: kLanguage: english
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.
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:
The modulus operator helps us extract the last digit/s of a number. For example:
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.
Learn live with top educators, chat with teachers and other attendees, and get your doubts cleared.
Our curriculum is designed by experts to make sure you get the best learning experience.
Interact and network with like-minded folks from various backgrounds in exclusive chat groups.
Stuck on something? Discuss it with your peers and the instructors in the inbuilt chat groups.
With the quizzes and live tests practice what you learned, and track your class performance.
Flaunt your skills with course certificates. You can showcase the certificates on LinkedIn with a click.