PYTHON OPERATORS
The other operators are Comparison operators: a = 10 and b = 30
- ( == ) equalto : here we put a == b if a is equal to b it will return true otherwise false so here it will return false
- ( != ) not equal to , here we put a != b if a is not equal to b then it will return true so here it will return true
- ( < ) less than , here we put a < b if a is less than b then it will return true other wise false so here it will return true
- ( > ) greater than, here we put a > b if a is greater than b then it will return true otherwise false so here it will return false
- ( >= ) greater than or equal to , here we put a >= b if a is greater than or equal to b then it will return true otherwise false so here it will return false
- (<=) less than or equal to : here we put a <= b if a is less than or equal to b then it will return true otherwise it will return false so here it will return true
Assignment operators
- ( = ) Equal to assignment : c= a+b here c is assigned the value of a+b
- ( += ) ADD AND : here we put as 10+= 5 by adding the two values 10 and 15 return 15
- ( -= ) Subtract AND: here we put 10 -= 5 by subtracting 5 from 10 return 5
- ( *= ) Multiply AND : here we put 10* = 5 by multiplying 5 and 10 returns 50
- ( /= ) Divide AND: here we put 10 / = 5 by dividing 10 by 5 returns 2
- (% = ) Modulus AND:here we put 21 %= 10 by modulus 21 and 10 and returns the coefficient is1
- (**=) Exponent AND:here we put 2**=4 is 2 to the power of 4 returns 16
- (//=) Floor Division: it is the same as a//=b is the same as a//b as explained earlier
Bit Wise Operators
The bitwise operators are which works on bits and performs bit by bit operation as simple computers knows only 0 and 1 the binary language. A bitwise operations operates on one or more bit patterns or binary numerals at the level of there induvidual bits it is a fast simple action supported by the processor and is used to manipulate values for calculation and comparison her are some examples given as a = 50
b = 25 the binary of this numbers is
a =0011 0010
b= 0001 1001
the operations can be done as
b = 25 the binary of this numbers is
a =0011 0010
b= 0001 1001
the operations can be done as
- a & b = 16 binary is 0001 0000 : It is a binary AND operator here operator copies a bit to the result if it exists in both operands
- a | b = 59 binary is 00111011: It is a binary OR operator It copies a bit if it exists in either operand
- a ^ b = 43 binary is 0010 1011: It is a binary XOR operator It copies the bit if it is set in one operand but not both
- ~a = -51 is the ones complement it is unary and has the effect of flipping the bits
- Binary Left shift operator << :the left operands value is moved by the number of bits specified by the right operand : a << 1 = 100 here a is 50
- Binary Right shift operator the left operands value is moved right by the number of bits specified by the right operand : a >> 1 = 25 here a is 50
No comments:
Post a Comment