Operators in Python – Python Tutorial for All

Operators in Python

  • An operator is a symbol used to perform mathematical or logical operations on values.
  • The values on which an operator works are called operands.
  • For example, in 10 + num, 10 and num are operands and + is an operator.

Types of Operators

  • Arithmetic operator
  • Relational operator
  • Assignment operator
  • Logical operator
  • Identity operator
  • Membership operator

Arithmetic Operators

Relational Operators

Logical Operator

Assignment Operator

Membership Operator

Identity Operators

Operator Precedence

  • In a mathematical or logical expression, operator precedence decides which operator will be executed first.
  • Operators with higher precedence are evaluated before operators with lower precedence.
  • It helps Python to perform calculations in the correct order.
  • The following table shows the precedence of different operators.
  • Parenthesis can be used to override the precedence of operators. The expression within () is evaluated first.
  • For operators with equal precedence, the expression is evaluated from left to right.

Do it by yourself

  1. Write a program to find average of five numbers
  2. Write a program to find cube of a given number.
  3. Write a program to convert oC to oF
  4. Write a program to swap values of two variables

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!
Scroll to Top