-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.python_operators.py
More file actions
59 lines (50 loc) · 1.07 KB
/
7.python_operators.py
File metadata and controls
59 lines (50 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Example 1: Arithmetic operators in Python
print('>>>> Example - 1 >>>>')
x = 15
y = 4
print('x + y =', x + y)
print('x - y =', x - y)
print('x * y =', x * y)
print('x / y =', x / y)
print('x // y =', x // y)
print('x ** y =', x ** y)
# Example 2: Comparison operators in Python
print('\n')
print('>>>> Example - 2 >>>>')
x = 10
y = 12
print('x > y is', x > y)
print('x < y is', x < y)
print('x == y is', x == y)
print('x != y is', x != y)
print('x >= y is', x >= y)
print('x <= y is', x <= y)
# Example 3: Logical Operators in Python
print('\n')
print('>>>> Example - 3 >>>>')
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)
# Example 4: Identity operators in Python
print('\n')
print('>>>> Example - 4 >>>>')
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1, 2, 3]
y3 = [1, 2, 3]
print(x1 is not y1)
print(x2 is y2)
print(x3 is y3)
# Example 5: Membership operators in Python
print('\n')
print('>>>> Example - 5 >>>>')
x = 'Hello world'
y = {1: 'a', 2: 'b'}
print('H' in x)
print('hello' not in x)
print(1 in y)
print('a' in y)