Skip to content

Commit 792175d

Browse files
Create __getitem__setitem__.py
1 parent 01de727 commit 792175d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

OOPS/__getitem__setitem__.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Indexer:
2+
def __init__(self):
3+
self.data=[1,2,3,4,5,6,7,8,9]
4+
def __getitem__(self,index):
5+
return self.data[index]
6+
def __setitem__(self,index,value):
7+
self.data[index]=value
8+
obj=Indexer()
9+
print(obj[4])
10+
obj[4]=100
11+
print(obj[4])
12+
for i in obj:
13+
print(i,end=" ")
14+
print('\n',list(obj))
15+
'''
16+
output:
17+
5
18+
100
19+
1 2 3 4 100 6 7 8 9
20+
[1, 2, 3, 4, 100, 6, 7, 8, 9]
21+
'''

0 commit comments

Comments
 (0)