You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want a class to behave like Python's range, it needs to do two main things:
Remember the range details: You need to keep track of where the range starts, where it should end, and how it steps (e.g., count by 1, 2, -1, etc.).
Know how to give the next number: When someone uses the class in a loop (like for x in MyRange), it needs to know what number to give next and when to stop.
Here’s how you’d do it step by step:
First, you make a init function. This is the setup where you save start, stop, and step.
Then, define iter. This makes the class an "iterable," meaning Python knows you can loop over it.
Finally, write next, where you calculate the next number to give out. If you're done (like the range is over), you tell Python to stop.
i hope this will help i can give example by code too if u want.
No description provided.
The text was updated successfully, but these errors were encountered: