Examples of operators in python programming
All Contributions
Membership operators :
x = 'Hello world'
y = {1:'a',2:'b'}
# Output: True
print('H' in x)
# Output: True
print('hello' not in x)
# Output: True
print(1 in y)
# Output: False
print('a' in y)
Identity operators :
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]
# Output: False
print(x1 is not y1)
# Output: True
print(x2 is y2)
# Output: False
print(x3 is y3)
Logical Operators :
x = True
y = False
print('x and y is',x and y)
print('x or y is',x or y)
print('not x is',not x)
total contributions (6)
python code to add 2 numbers to each other and print the result