Sitemap
Laxmi prasanna

Laxmi prasanna

3 min readOct 16, 2023

--

PYTHON OPERATORS :

Operators are special symbols that perform operations on variables and values. There are 7 types of operators are given below:

  • Arithmetic operators.
  • Assignment operators.
  • Comparison operators.
  • Logical operators.
  • Identity operators.
  • Membership operators.
  • Bitwise operators.

* Arithmetic operations:

An Arithmetic Operator is a mathematical function that performs a calculation on two operands. The different types of arithmetic operators include addition, subtraction, multiplication, division, modulus, exponentiation and floor division.
x,y = 15,4
print(x+y) = 19
print(x-y) = 11
print(x*y) = 60
print(x/y) = 3.25
print(x**y) = 50625
print(x//y) = 3
print(x%y) = 3

* Assignment Operators:

The simple assignment operator is the most commonly used operator in Python. It is used to assign a value to a variable. The syntax for the simple assignment operator is: variable = value. Here, the value on the right-hand side of the equals sign is assigned to the variable on the left-hand side.

  • Operator Assignment (=)
  • Operator Addition (+=)
  • Operator Subtraction (-=)
  • Operator Multiplication (*=)
  • Operator Division (/=)
  • Operator Modulus (%=)
  • Operator Exponentiation (**=)
  • Operator Floor Division (//=)

*COMPARISION OPERATORS:

A comparison operator in python, also called python relational operator, compares the values of two operands and returns True or False based on whether the condition is met.

Get Laxmi prasanna’s stories in your inbox

Join Medium for free to get updates from this writer.

Python has six comparison operators:

less than ( < )

less than or equal to ( <= )

greater than ( > )

greater than or equal to ( >= )

equal to ( == )

and not equal to ( != )

*LOGICAL OPERATIONS:

Logical Operators in Python are used to perform logical operations on the values of variables. The value is either true or false. We can figure out the conditions by the result of the truth values.

There are mainly three types of logical operators in python:

logical AND, logical OR and logical NOT

  • logical operators(and, not, or)
    x, y, z = True, False, True
    print( x and y, x and z)
    print( x or y, x or z, y or y)
    print( not x)

*IDENTITY OPERATIONS:

Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location: Operator, Description.

  • identity operators (is, is not)
    inta , intb = 250,250
    lista, listb = [1, 2, 3], [1, 2, 3]
    listc = lista
    stra, strb = ‘string’, ‘string’
    strc = stra
    lista == listb, lista is listb, lista is listc

*MEMBERSHIP OPERATIONS:Membership operators are operators used to validate the membership of a value.

  • It test for membership in a sequence, such as strings, lists, or tuples. in operator :
  • The ‘in’ operator is used to check if a value exists in a sequence or not.
  • Membership operations (in, not in)
    x, y = [10, 11, 15], ‘string’
    11 in x, ‘z’ not in y

*BITWISE OPERATIONS:

  • Python bitwise operators are used to perform bitwise calculations on integers.
  • The integers are converted into binary format and then operations are performed bit by bit, hence the name bitwise operators.
  • Python bitwise operators work on integers only and the final output is returned in the decimal format.
  • For example, a logical AND (&) of each bit pair results in a 1 if both the first AND second bits are 1. If only one bit is a 1, the result is 0.

--

--