-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathChapter_6th.py
91 lines (76 loc) · 1.43 KB
/
Chapter_6th.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Example 1
a = 21
b = 10
c = 0
c = a + b
print (" Value of c is ", c)
c = a - b
print (" Value of c is ", c )
c = a * b
print( " Value of c is ", c )
c = a / b
print( " Value of c is ", c )
# Output
# Value of c is 31
# Value of c is 11
# Value of c is 210
# Value of c is 2.1
# Example 2
x = 10
y = 12
print('x > y is',x>y)
# Output: x > y is False
print('x < y is',x<y)
# Output: x < y is True
print('x == y is',x==y)
# Output: x == y is False
print('x != y is',x!=y)
# Output: x != y is True
print('x >= y is',x>=y)
# Output: x >= y is False
print('x <= y is',x<=y)
# Output: x <= y is True
# 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)
# Output
# x and y is False
# x or y is True
# not x is False
# Example 4
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
print(x1 is not y1)
print(x2 is y2)
# Output
# False
# True
# 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)
# Output
# True
# True
# True
# False
# Example 6
a = 10
b = 4
print("a & b =", a & b) # Print bitwise AND operation
print("a | b =", a | b) # Print bitwise OR operation
print("~a =", ~a) # Print bitwise NOT operation
print("a ^ b =", a ^ b) # print bitwise XOR operation
# Output
# a & b = 0
# a | b = 14
# ~a = -11
# a ^ b = 14