Python Unit 1
Python Unit 1
UCS18601 - PYTHON
Mr. D.SIVA
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE
SRM IST, RAMAPURAM
Types of Operator
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
//Floor division Floor Division - The division of operands where the result is the 9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -
quotient in which the digits after the decimal point are removed. 11.0//3 = -4.0
But if one of the operands is negative, the result is floored, i.e.,
rounded away from zero (towards negative infinity) −
!= If values of two operands are not equal, then condition becomes true. (a != b) is true.
<> If values of two operands are not equal, then condition becomes true. (a <> b) is true. This is similar to
!= operator.
> If the value of left operand is greater than the value of right operand, then (a > b) is not true.
condition becomes true.
< If the value of left operand is less than the value of right operand, then condition (a < b) is true.
becomes true.
>= If the value of left operand is greater than or equal to the value of right operand, (a >= b) is not true.
then condition becomes true.
<= If the value of left operand is less than or equal to the value of right operand, (a <= b) is true.
then condition becomes true.
+= 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
>> Binary Right The left operands value is moved right by the number of bits specified by the
Shift right operand. a >> 2 = 15 (means 0000 1111)
x or y If x is false, then y else x Only evaluates the second argument(y) if the firs one is
false
x and y If x is false, then x else y Only evaluates the second argument(y) if the first one(x) is
True
Example 2 :
x=5
y = 10
if x > 6 and y < 20:
print('OK')
Example 3 :
a=0
b=2
c=3
x = a or c
print(x)