-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson5.py
More file actions
109 lines (94 loc) · 2.68 KB
/
lesson5.py
File metadata and controls
109 lines (94 loc) · 2.68 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
""" Python Operators """
""" Arithmetic Operators """
print(" --- Arithmetic Operators --- ")
x=11
y=2
print(x+y) # Addition
print(x-y) # Subtraction
print(x*y) # Multiplication
print(x/y) # Division
print(x%2) # Modulus
print(x**y) # Exponentiation
print(x//y) # Floor division
""" Assignment Operators """
print(" --- Assignment Operators --- ")
a = 5
print(a)
a+=3
print(a)
a = 6
a-=3
print(a)
a = 5
a*=3
print(a)
a = 7
a/=2
print(a)
a=11
a%=2
print(a)
a=90
a//=3
print(a)
a=2
a**=4
print(a)
a=5
a&=3
print(a)
a=4
a|=3
print(a)
a=2
a^=3
print(a)
a=20
a>>=2
print(a)
a=15
a<<=2
print(a)
""" Comparison Operators """
print(" --- Comparison Operators --- ")
x=3
y=5
print(x==y) # Equal
print(x!=y) # Not Equal
print(x>y) # Greater than
print(x<y) # Less than
print(x>=y) # Greater than or Equal to
print(x<=y) # Less than or Equal to
""" Python Logical Operators """
print(" --- Python Logical Operators --- ")
x=5
print(x>3 and x<10) # and - returns true because both conditions are true
print(x>3 or x<4) # or - returns true because one of the conditions is true
print(not(x>3 and x<10)) # not - returns False because not is used to reverse the result
""" Python Identity Operators """
print(" --- Python Identity Operators --- ")
x = ['apple', 'banana']
y = ['apple', 'banana']
z=x
print(" --- is --- ")
print(x is z) # returns True because z is the same object ads x
print(x is y) # returns False because x is not the same object as y, even if they have the same content
print(x==y) # to demonstrate the difference between 'is' and '=='. This comparison returns True because x is equal to y
print(" --- is not --- ")
print(x is not z) # returns False because z is the same object as x
print(x is not y) # returns True because x is not the same object as y, even if they have the same content
print(x != y) # to demonstrate the difference between 'is not' and '!='. This comparison returns False because x is equal to y
""" Python Membership Operators """
print(" --- Python Membership Operators --- ")
x=["pineapple", "Banana", "Orange"]
print("pineapple" in x) # returns true because a sequence with the value "pineapple is in the list.
print("Mango" in x) # returns False because a sequence with the value "Mango" is not in the list
""" Python Bitwise Operators """
"""
& (and) - Sets each bit to 1 if both bits are 1
| (or) - Sets each bit to 1 if one of the bits is one
^ (xor) - Sets each bit to 1 if only one of two bits is 1
~ (not) - Inverts all the bits
<< (zero fill/left shift) - Shift left by pushing zeros in from the right and let the leftmost bits fall off
>> (Signed/ right shift) - Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off
"""