<jupyter_start><jupyter_text>Types of OperatorPython language supports the following types of operators:* Arithmetic Operators* Comparison (Relational) Operators* Assignment Operators* Logical Operators* Bitwise Operators* Membership Operators* Identity Operators  Arithmetic**Operator**|**Description**|**Example**:-----:|:-----:|:-----:+ Addition|Adds values on either side of the operator.|a + b = 31- Subtraction|Subtracts right hand operand from left hand operand.|a – b = -11* Multiplication|Multiplies values on either side of the operator|a * b = 210/ Division|Divides left hand operand by right hand operand|b / a = 2.1% Modulus|Divides left hand operand by right hand operand and returns remainder|b % a = 1** Exponent|Performs exponential (power) calculation on operators|a**b =10 to the power 20//|Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity):|9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0<jupyter_code>a, b = 10, 21.
# Addition
a + b
# Substraction
a - b
# Multiplcation
a * b
# Division
b / a
# Modulus
b % a
# Exponent
a**b
# Floor Division
b // a
11.0 // 3 
-11.0 // 3<jupyter_output><empty_output><jupyter_text>Comparison**Operator**|**Description**|**Example**:-----:|:-----:|:-----:==|If the values of two operands are equal, then the condition becomes true.|(a == b) is not true.!=|If values of two operands are not equal, then condition becomes true.|(a!= b) is true.>|If the value of left operand is greater than the value of right operand, then condition becomes true.|(a > b) is not true.<|If the value of left operand is less than the value of right operand, then condition becomes true.|(a < b) is true.>=|If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.|(a >= b) is not true.<=|If the value of left operand is less than or equal to the value of right operand, then condition becomes true.|(a <= b) is true.<jupyter_code># == is Equal
a == b
a == 10
# != is not Equal
a != b
a != 10
# > greater than
b > a
# < less than
a < b
# >= greater or equal
b >= a
b >= 21
# <= less or equal
a <= b
a <= 10<jupyter_output><empty_output><jupyter_text>Assignment**Operator**|**Description**|**Example**:-----:|:-----:|:-----:=|Assigns values from right side operands to left side operand|c = a + b assigns value of a + b into c+= Add AND|It adds right operand to the left operand and assign the result to left operand|c += a is equivalent to c = c + a-= Subtract AND|It subtracts right operand from the left operand and assign the result to left operand|c -= a is equivalent to c = c - a*= Multiply AND|It multiplies right operand with the left operand and assign the result to left operand|c *= a is equivalent to c = c * a/= Divide AND|It divides left operand with the right operand and assign the result to left operand|c /= a is equivalent to c = c / a%= Modulus AND|It takes modulus using two operands and assign the result to left operand|c %= a is equivalent to c = c % a**= Exponent AND|Performs exponential (power) calculation on operators and assign value to the left operand|c **= a is equivalent to c = c ** a//= Floor Division|It performs floor division on operators and assign value to the left operand|c //= a is equivalent to c = c // a<jupyter_code># = Assign
c = a + b
print(c)
# += Add and
c += a # is equivalent c = c + a
print(c)
# Substract and
c -= a # is equivalent c = c - a
print(c)
# *= multiply and
c *= a # is equivalent c = c * a
print(c)
# /= Divide and
c /= a # is equivalent c = c/a
print(c)
# %= Modulus and
c %= a # is equivalent c = c % a 
print(c)
# **= exponent and
c**=a # is equivalent c = c**a
print(c)
# //= Floor division
c //= a # is equivalent c = c // a
print(c)<jupyter_output>0<jupyter_text>BitwiseBitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60; and b = 13; Now in binary format they will be as follows:a = 0011 1100b = 0000 1101-----------------a&b = 0000 1100a|b = 0011 1101a^b = 0011 0001~a = 1100 0011Python's built-in function bin() can be used to obtain binary representation of an integer number.**Operator**|**Description**|**Example**:-----:|:-----:|:-----:& Binary AND|Operator copies a bit, to the result, if it exists in both operands|(a & b) (means 0000 1100)^ Binary XOR|It copies the bit, if it is set in one operand but not both.|(a ^ b) = 49 (means 0011 0001)~ Binary Ones Complement|It is unary and has the effect of 'flipping' bits.|(~a ) = -61 (means 1100 0011 in 2's complement form due to a signed binary number.<< Binary Left Shift|The left operand's value is moved left by the number of bits specified by the right operand.|a << = 240 (means 1111 0000)>> Binary Right Shift|The left operand's value is moved right by the number of bits specified by the right operand.|a >> = 15 (means 0000 1111)Binary OR|It copies a bit, if it exists in either operand.|(a \ b) = 61 (means 0011 1101)<jupyter_code>a = 60
b = 13
print(bin(a))
print(bin(b))
# & Binary and
print(a&b)
print(bin(a&b))
# | Binary or
print(a|b)
print(bin(a|b))
# ^ Binary xor
print(a^b)
print(bin(a^b))
# << Binary left shift
print(a<<2)
print(bin(a<<2))
print(a<<1)
print(bin(a<<1))
# >> Binary right shift
print(a>>2)
print(bin(a>>2))
print(a>>1)
print(bin(a>>1))<jupyter_output>15
0b1111
30
0b11110<jupyter_text>Logical OperatorsThe following logical operators are supported by Python language. Assume variable a holds True and variable b holds False then:<jupyter_code>a = True
b = False
a and b
a or b
not(a and b)<jupyter_output><empty_output><jupyter_text>Identity OperatorIdentity operators compare **the memory locations** of two objects.**Operator**|**Description**|**Example**:-----:|:-----:|:-----:is|Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.|x is y, here is results in 1 if id(x) equals id(y).is not|Evaluates to false if the variables on either side of the operator point to the same object and true otherwise.|x is not y, here is notresults in 1 if id(x) is not equal to id(y).<jupyter_code>a = 20 
b = 20
print('Line 1','a=',a,':',id(a), 'b=',b,':',id(b))
if ( a is b ):
   print ("Line 2 - a and b have same identity")
else:
   print ("Line 2 - a and b do not have same identity")
if ( id(a) == id(b) ):
   print ("Line 3 - a and b have same identity")
else:
   print ("Line 3 - a and b do not have same identity")
# Change value of b
b = 30
print ('Line 4','a=',a,':',id(a), 'b=',b,':',id(b))
if ( a is not b ):
   print ("Line 5 - a and b do not have same identity")
else:
   print ("Line 5 - a and b have same identity")<jupyter_output>Line 5 - a and b do not have same identity
{'fraction_non_alphanumeric': 0.13428905792861323, 'fraction_numerical': 0.03071971913399649, 'mean_word_length': 3.9905109489051096, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '283610', 'license': 'MIT', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2185, 'n_words': 981, 'path': 'Day 2/01 Basic Operator.ipynb', 'repo_name': 'ilmimris/python-course-himastron-2019', 'size': '6836'}