-
Notifications
You must be signed in to change notification settings - Fork 1
/
OOPS_14.py
176 lines (128 loc) · 2.12 KB
/
OOPS_14.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
class Employee:
no_of_leaves = 8
def __init__(self, aname, asalary, arole):
self.name = aname
self.salary = asalary
self.role = arole
def printdetails(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"
@classmethod
def change_leaves(cls, newleaves):
cls.no_of_leaves = newleaves
def __add__(self, other):
return self.salary + other.salary
def __truediv__(self, other):
return self.salary / other.salary
def __repr__(self):
return f"Employee('{self.name}', {self.salary}, '{self.role}')"
#"""Firstly simple"emp1" would search for '__str__' THEN '__repr__' """
def __str__(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"
emp1 =Employee("Harry", 345, "Programmer")
emp2 =Employee("Rohan", 55, "Cleaner")
print(str(emp1))
print(repr(emp1))
"""Addition a + b add(a, b)
Concatenation
seq1 + seq2
concat(seq1, seq2)
Containment Test
obj in seq
contains(seq, obj)
Division
a / b
truediv(a, b)
Division
a // b
floordiv(a, b)
Bitwise And
a & b
and_(a, b)
Bitwise Exclusive Or
a ^ b
xor(a, b)
Bitwise Inversion
~ a
invert(a)
Bitwise Or
a | b
or_(a, b)
Exponentiation
a ** b
pow(a, b)
Identity
a is b
is_(a, b)
Identity
a is not b
is_not(a, b)
Indexed Assignment
obj[k] = v
setitem(obj, k, v)
Indexed Deletion
del obj[k]
delitem(obj, k)
Indexing
obj[k]
getitem(obj, k)
Left Shift
a << b
lshift(a, b)
Modulo
a % b
mod(a, b)
Multiplication
a * b
mul(a, b)
Matrix Multiplication
a @ b
matmul(a, b)
Negation (Arithmetic)
- a
neg(a)
Negation (Logical)
not a
not_(a)
Positive
+ a
pos(a)
Right Shift
a >> b
rshift(a, b)
Slice Assignment
seq[i:j] = values
setitem(seq, slice(i, j), values)
Slice Deletion
del seq[i:j]
delitem(seq, slice(i, j))
Slicing
seq[i:j]
getitem(seq, slice(i, j))
String Formatting
s % obj
mod(s, obj)
Subtraction
a - b
sub(a, b)
Truth Test
obj
truth(obj)
Ordering
a < b
lt(a, b)
Ordering
a <= b
le(a, b)
Equality
a == b
eq(a, b)
Difference
a != b
ne(a, b)
Ordering
a >= b
ge(a, b)
Ordering
a > b
gt(a, b)
"""