What are different basic operators in Python?



Operators in Python are classified as −

Arithmetic operators

  • + for addition
  • - for subtraction
  • * for multiplication
  • / for division
  • // for floor division
  • % for modulo or remainder

Relational operators

  • > for greater than
  • >= for greater than or equal to
  • < for less than
  • <= for less than or equal to
  • == for is equal to
  • != for is not equal to

Logical operators

  • and − true only if both operands are true
  • or − true even if one operands is true
  • not − true if operand is false and vice versa

bitwise operators

  • & for bitwise AND
  • | for bitwise OR
  • ~ for bitwise NOT
  • ^ for bitwise XOR
  • >> for bitwise right-shift
  • << for bitwise left -shift

Assignment operators

  • = assign value on right to variable on left
  • += add and assign
  • -= subtract and assign
  • *= multiply and assign
  • /= divide and assign

Identity operators

  • is − true if operands are identical
  • is not − false if operands are not identical

Membership operators

  • in − true if value present in sequence
  • not in − false if value not present in sequence

 


Advertisements