__author__ = "Narendra Boyina"
# -----------------------------------------------------------------------------
# Copyright (c) 2025 BR Technologies PVT LTD
#-----------------------------------------------------------------------------
"""
Topics to be covered in today's class: Operators continuation
--> Bitwise operators
--> Membership operators
"""
"""
6. Membership operators:
====================
The membership operators in Python are used to test whether a value is found
within a sequence (such as strings, lists, or tuples ......)
--> Two membership operators ("in", "not in") exist in Python
"""
in – evaluates to True if the value in the left operand appears in the sequence
found in the right operand
"""
# print('Hello' in 'Hello world!')
# print('!' in 'Hello world!')
# print('house' in 'Hello world!')
# print('hello' in 'Hello world!') # # False // note that Python is case-sensitive
"""not in – evaluates to True if the value in the left operand doesn’t appear in
the sequence found in the right operand"""
# print('Hello' not in 'Hello world!') # False
# print('car' not in 'Hello world!') # True
"""
7. Bitwise operators
================
It operates bit by bit, hence the name.
For example, 2 is 10 in binary, and 7 is 111. ( 128 64 32 16 8 4 2 1 code)
"""
# print("******** Bitwise operators ********")
X = 10 # (0000 1010 in binary)
Y = 7 # (0000 0111 in binary)
# print("X&Y value is", X & Y) # & Binary AND
# print("X|Y value is", X | Y) # | Binary OR
# print("X^Y value is", X ^ Y) # ^ Binary XOR if both are 1 then result is 0
# Y = 7
# print(" ~Y value is", ~Y) # ~ Bitwise Complement
# Bitwise Complement of value is -(value+1) ==> -(-7+1) ==>-(-6) ==> 6
# # Ex: x = 7 ==> ~x ==> -8
# # y = 12 ==> ~y ==> -13
# print(" x<<2 value is", X << 2) # << Binary Left Shift
# print(" Y>>2 value is", Y >> 2)Author: Boyina Narendra
Supporting Author: M. Meera Sindhu
Request: If you find this information useful, please provide your valuable comments
No comments:
Post a Comment