Examples of operators in python programming

0

Operators are special symbols in Python that carry out arithmetic or logical computation

example:

>>> 2+3
5

All Contributions

python code to add 2 numbers to each other and print  the result

num1=10
num2=14
result=num1+num2
print(result)

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)

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)

New to examplegeek.com?

Join us