MCPcopy Index your code
hub / github.com/qiwsir/StarterLearningPython / MyRange

Class MyRange

2code/21401.py:7–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5the interator as range()
6"""
7class MyRange(object):
8 def __init__(self, n):
9 self.i = 1
10 self.n = n
11
12 def __iter__(self):
13 return self
14
15 def next(self):
16 if self.i <= self.n:
17 i = self.i
18 self.i += 1
19 return i
20 else:
21 raise StopIteration()
22
23if __name__ == "__main__":
24 x = MyRange(3)

Callers 1

21401.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected