0% found this document useful (0 votes)
2 views3 pages

Operators Part 2 - Python

The document provides an overview of various operators in Python, including relational, logical, bitwise, and membership operators. Each operator is described with its name, meaning, and examples of usage. Additionally, it briefly mentions identity operators, although details on them are not included.

Uploaded by

shobharoy79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Operators Part 2 - Python

The document provides an overview of various operators in Python, including relational, logical, bitwise, and membership operators. Each operator is described with its name, meaning, and examples of usage. Additionally, it briefly mentions identity operators, although details on them are not included.

Uploaded by

shobharoy79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Operators in Python

3. Rela3onal or Comparison Operators


Comparison operators are used to compare values on le: hand side and right hand side and
find rela3on between them.

Operators Name Meaning


< Less then Return True if le: operand is less than the
right
> Greater then Return True if le: operand is greater then
the right
== Equal to Return True if both operands are equal
!= Not equal to Return True if both operands are not
equal
>= Greater then or Return True if le: operand is greater than
equal to or equal to right operand
<= Less then or equal to Return True if le: operand is less than or
equal to right operand

Example:
n1 = 2
n2 = 3
num = n1 < n2
print(num)

4. Logical Operators
Logical operators are used to combine two or more condi3ons and perform the logical
opera3ons using logical AND, OR, NOT

Operator Name Meaning


and Logical AND Return True if both the operands returns
true
or Logical OR Return True if either or the operand
returns true
not Logical NOT Return True if operand is false and return
False if operand is True

Example:
a = 2 < 3 and 4 > 3
print(“value of a =”, a)
5. Bitwise Operators
Bitwise operator works on bits and performs bit by bit opera3on. Assume if a = 60; and b =
13; Now in the binary format their values will be 00111100 and 00001101 respec3vely.

Operator Name Meaning


& Binary AND Operator copies a bit to the result if it
exists in both operands
| Binary OR It copies a bit if it exists in either operand
^ Binary XOR It copies a bit if it set in one operand but
not both
~ Binary Ones It is unary and has the effect of flipping
Complement bits
<< Binary Le: Shi: The le: operand value is moved le: by the
number of bits specified by the right
operand
>> Binary Right Shi: The le: operand value is moved right by
the number of bits specified by the right
operand

Example
A=60
B=13
C=0
C= A & B
print (C)

6. Membership Operators
Python’s membership operators test for membership in a sequence, such as strings, lists, or
tuples.
Operator Meaning Example
in Evaluate to true if x in y, here in results in a 1 if x is member
it finds a variable in of sequence y.
the specified
sequence and false
otherwise
not in Evaluate to true if x not in y, here not in results in a 1 if x is
it does not finds a not a member of sequence y.
variable in the
specified sequence
and false otherwise

Example

A= 10
B = 20
List = [1, 2, 3, 4, 5];
If ( A in List ):
Print(“ A is available”);
else:
Print(“A is not available”)

7. Iden3ty Operator ……………………

You might also like