operators in python

Operators are used to perform operations on variables and values. There are 7 types of basic operators in python. They are as folluws :


  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Identity operators
  • Membership operators
  • Bitwise operators
Python Arithmetic Operators

 
Operator

NameDescription eg: 
 + AdditionAdds values on either side of the operator a+b
 -Subtraction Subtracts values on either side of the operator  a-b
 * Multiplication Multiplies values on either side of the operator a*b
 /Division Divides values on either side of the operator   a/b
 ModulusDivides left hand operand by right hand operand and returns remainder a%b
** ExponentiationPerforms exponential calculation on operatorsa**b 
// Floor DivisionThe division of operands where the result is quotient in which the digits after the decimal points are removed.a//b 


Python Assignment Operators

 
Operator

NameDescription eg: 
 =EqualAssigns values from right side operands to left side operanda=b 
+=Addition AndAdds right operand to the left operand and assign the result to left operanda+=b
 -=Subtraction AndSubtracts right operand from the left operand and assign the result to left operand a-=b
 *=Multiplication AndMultiplies right operand with the left operand and assign the result to left operanda*=b
/=Division AndDivides left operand with the right operand and assign the result to left operand a/=b
%=Modulus AndTakes modulus using two operands and assign the result to left operanda%=b 
**= Exponent AndPerforms exponential calculation on operators and assign value to the left of the operanda**=b 
//= Floor Division Performs floor division on operators and assign value to the left of the operanda//=b 


Python Comparison Operators

 
Operator

NameDescription eg: 
 ==Double Equal toTrue if LHS=RHSa==b 
!=Not equal toTrue if LHS not equal to RHSa!=b
<Less thanTrue if LHS less than RHS a<b
 >Greater thanTrue if LHS greater than RHSa>b
<=Less than or equal toTrue if LHS less than or equal to RHS a<=b
>=Greater than or equal toTrue if LHS greater than or equal to RHSa>=b 
<>Not Equal toSame as !=a<>b 


Python Logical Operators

 
Operator

NameDescription eg: 
andLogical ANDTrue if both operands are truea and b 
orLogical ORTrue if one of the statement is truea or b
notLogical NOTTrue if the result is false a not b


Python Identity Operators

 
Operator

NameDescription eg: 
isisTrue if both variables point to the same objecta is b 
is notis notFalse if both variables point to the same objecta is not b


Python Membership Operators

 
Operator

NameDescription eg: 
inisTrue if it finds a variable in the specified sequencea in b 
not inis notTrue if it does not finds a variable in the specified sequencea not in b


Python Bitwise Operators

 
Operator

NameDescription eg: 
 &ANDSets each bit to 1 if both bits are 1a==b 
|ORSets each bit to 1 if one of two bits are 1a!=b
^XORSets each bit to 1 if only one of two bits is 1 a<b
 ~NOTInverts all the bitsa>b
<<Left ShiftShifts left by pushing zero in from right and let the leftmost bits fall off a<=b
>>Right ShiftShifts right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall offa>=b 


Prev
Next

Comments

Popular posts from this blog

Node.js Cheat Sheet

Enhancing Supply Chain Security and Cloud-Native Development with Chainguard

Codeigniter ! Simple But Powerful