Python Operators with Syntax

Python Operators with Syntax

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.

  1. >>> 3+4
  2. 7

 Subtraction(-)

Subtracts the value on the right from the one on the left.

  1. >>> 3-4
  2. -1

Start with Python installation first.

Multiplication(*)

Multiplies the values on either side of the operator.

  1. >>> 3*4
  2. 12

Division(/)

Divides the value on the left by the one on the right. Notice that division results in a floating-point value.

  1. >>> 3/4
  2. 0.75

 Exponentiation(**)

Raises the first number to the power of the second.

  1. >>> 3**4
  2. 81

 Floor Division(//)

Divides and returns the integer value of the quotient. It dumps the digits after the decimal.

  1. >>> 3//4
  2. 0
  3. >>> 4//3
  4. 1
  5. >>> 10//3
  6. 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.

  1. >>> 3<4
  2. True

b. Greater than(>)

It checks if the value on the left of the operator is greater than the one on the right.

  1. >>> 3>4
  2. 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.

  1. >>> 7<=7
  2. 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.

  1. >>> 0>=0
  2. 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.

Read Complete Article >>

Related Post -

Let us see Python Lists with Examples

Learn more about Python Tuples with Syntax


要查看或添加评论,请登录

社区洞察

其他会员也浏览了