Python Operators with Syntax
Malini Shukla
Senior Data Scientist || Hiring || 6M+ impressions || Trainer || Top Data Scientist || Speaker || Top content creator on LinkedIn || Tech Evangelist
Introduction to Python Operators
Python identifiers fall into 7 categories:
1) Arithmetic
2) Relational
3) Assignment
4) Logical
5) Membership
6) Identity
7) Bitwise
An operator is a symbol that performs an operation on one or more operands. An operand is a variable or a value on which we perform the operation. Let us revise syntax in python before we start with the operators in Python. Also it is recommended to revise variable types in Python for proper programming.
3. Arithmetic Operators
These include python operators for basic mathematical operations.
Before starting with operators in python, let us see basics of Python.
a. Addition(+)
Adds the values on either side of the operator.
- >>> 3+4
- 7
Subtraction(-)
Subtracts the value on the right from the one on the left.
- >>> 3-4
- -1
Start with Python installation first.
Multiplication(*)
Multiplies the values on either side of the operator.
- >>> 3*4
- 12
Division(/)
Divides the value on the left by the one on the right. Notice that division results in a floating-point value.
- >>> 3/4
- 0.75
Exponentiation(**)
Raises the first number to the power of the second.
- >>> 3**4
- 81
Floor Division(//)
Divides and returns the integer value of the quotient. It dumps the digits after the decimal.
- >>> 3//4
- 0
- >>> 4//3
- 1
- >>> 10//3
- 3
Learn more in detail Bitwise Operator in Python with Syntax
4. Relational Operators
Let’s see about relational python operators.
Relational operators carry out comparison between operands. They tell us whether an operand is greater than the other, lesser, equal, or a combination of those.
a. Less than(<)
This operator checks if the value on the left of the operator is lesser than the one on the right.
- >>> 3<4
- True
b. Greater than(>)
It checks if the value on the left of the operator is greater than the one on the right.
- >>> 3>4
- False
Refer Top 10 Python Books to Learn Python Programming
c. Less than or equal to(<=)
It checks if the value on the left of the operator is lesser than or equal to the one on the right.
- >>> 7<=7
- True
d. Greater than or equal to(>=)
It checks if the value on the left of the operator is greater than or equal to the one on the right.
- >>> 0>=0
- True
e. Equal to(= =)
This operator checks if the value on the left of the operator is equal to the one on the right. 1 is equal to the Boolean value True, but 2 isn’t. Also, 0 is equal to False.
Related Post -
Let us see Python Lists with Examples
Learn more about Python Tuples with Syntax