NUMBERS AND OPERATORS
Numbers are normal operand values
which are used to perform set of task or operations using an operator. Numbers can be integers, decimal value, etc.
There are many operators in Python.
Some of them are listed below:
Ø Arithmetic operators
Ø Comparison
operators
Ø Logical
operators
Ø Bitwise
operators
Ø Assignment
operators
In this blog we will see about
Arithmetic operators and understand how to use it with Python IDLE to perform
certain calculations.
PYTHON ARITHMETIC OPERATORS
OPERATOR
|
DESCRIPTION
|
EXAMPLE
|
Addition (+)
|
Adds two values
|
5+6 = 11
|
Subtraction (-)
|
Subtracts
|
5-3 = 2
|
Multiplication (*)
|
Multiplies two values
|
4*8 = 32
|
Division (/)
|
Divide by right hand operand
|
6/3 = 2
|
Modulus (%)
|
Divides and gives the remainder
|
6%3 = 0
|
Exponential (**)
|
Performs power calculations on operand
|
2**4 = 32
|
Double slash (//)
|
Rounds the float to the nearest value integer.
Positive case: Round to positive existing integer
Negative case: Round towards negative infinity
|
13//2 = 6
-13//2 = -7
|
The priority or hierarchy of
operators is defined using a standard rule of BODMAS which means Brackets,
Division, Multiplication, Addition and Subtraction. In this priority a given
equation with multiple operators can be solved.
Other operators will be explained in other
blogs.
Comments
Post a Comment