Level 10 : What happens when we execute this iterator code?


class StepIterator:
    def __init__(self, start, step, end):
        self.current = start
        self.step = step
        self.end = end

    def __iter__(self):
        return self

    def __next__(self):
        if self.current >= self.end:
            raise StopIteration
        value = self.current
        self.current += self.step
        return value

it = StepIterator(2, 3, 10)
print(list(it))

Author: SandhyaR | Tags: iterator | 1859+ Python FAQs | Share
map-function | conditional-statements | conditional-statement | conditional-statement | application | data-structure | booleans | append | integer | constructor | assignment-operators | virtual-environment | odd-number | loop-control-statements | defining-functions | data-type | class-and-inheritance | list-comprehension | managing-directories-with-os-and-shutil | creating-custom-modules | namespace | anchors-(^,-$) | control-flow | print-statement | complex-number | data-structures-in-python | syntax-error | regex | string-iteration | sys | syntax | stack | compute | list-methods-and-slicing | datetime | recurssion | basic | arithmetic-expression | static-method | python-repl | bitwise-operator | datetime.date,-datetime.time,-datetime.datetime | list-method | default-mutable-argument | comprehension | async | string-formatting | recursion | deep-copy | collection | using-os-and-pathlib-modules | version-check | random | collections | aggregating-data-with-functools.reduce() | postfix | lists | dictionary-comprehensions | command-line-parsing | split | condition | string-method | built-in-function | data-type | center | attribute | datatype | arbitrary-arguments-(*args,-**kwargs) | debugging | dataframe-and-series-objects | design-principle | range | data_structure | return-statement | control-statement | global-keyword | dictionary | sorted | type_conversion | tuples | advanced-file-operations | sys-module | list-slicing | counter-function | docstring | boolean-masking | logical-operator | raise-statement | sorting-and-ranking | dictionaries | reading:-read(),-readline(),-readlines() | feature | regular-expression | class-and-instance-variable | error-handling | fabs-function | class | multiple-inheritance | formatting-with-strftime | class-and-object | using-join()-and-is_alive()-methods | global-variable | multiprocessing | unit-testing | format | file_handling | comment | multiple-except-blocks | generator | gil | access-modifier | tuple-unpacking | dicts | operators | module | array | math | operator-overloading | thread | data-structures | tuple | data-types | list-mutation | global-variable | file-handling | matrix-list-comprehension | functions | time-series-with-pandas | expression | pandas | python-django | error | copy | boolean-and-non-boolean | pass | memory-management | function | overriding-methods | bitwise | using-else-and-finally | quantifiers-(*,-+,-?,-{}) | generators | update | loop-control | overflow | difference-between-threads-and-processes | using-yield-in-functions | matrix | regular-expressions | string-method | python_version | file | single-inheritance | literal-characters-and-special-characters | strings | conversion | why-use-multiprocessing-over-threading?-(gil) | working-with-file-paths | dictionary-methods | handling-missing-values-(fillna,-dropna) | typeerror | min-max-function | complex | namedtuple | set-operation | built-in-function | factorial-function | type-conversion | iterator | descriptors | nested-loop | pickling--unpickling | benefit | decorator | syntax-error | sum-function | join | parsing-with-strptime | print | encapsulation | sorting | assert | mathematics | __init_subclass__ | numpy | control-flow | assignment-operator | operations | object-attribute | shallow-copy | exponentiation | list-comprehension | round-function | round | asyncio | reading-and-writing-large-files-efficiently | identity-operator | slice | binary | binary-operation | iterable | scientific-notation | objects | data-structure | frozenset | generators-in-python | touples | zip-function | lambda-functions | asyncio-module | key-value-pairs | immutable-data-type | bitwise-operator | python-operators | decimal | rollback | filter-function | memory | indentation | counter | python | thread-synchronization | max-min | invalid-list | destructor | inheritance | yield | default-arguments | introduction-to-threads | sum() | zfill-function | list-indexing | python-syntax-and-structure | installation | pep | methods | input-function | magic-method | opening-files-(open()) | method | heap-memory | introduction-to-python | def | built-in-modules | operator-or | formal-and-actual-parameter | software-design | mysql | function-argument | context-manager | creating-and-starting-threads | init | joining-and-merging-dataframes | operator-and | built-in | identifier | with-statement | library | type-conversion | oops | sets | math-copysign | enumerate() | list-comprehensions | data-type-conversions | multithreading | for | escape-operator | comparison | test-discovery | precedence | inherit | parameter | __future__ | writing:-write(),-writelines() | classes | syntaxerror | call | swapping | polymorphism | arithmetic-operation | directory-operations | type-conversion-and-casting | using-lists-as-stacks | head-and-tail | using-map()-for-transformations | threading | precedence-and-associativity | slicing | mutable | identity-operator | integers | while-loops | __all__-attribute | string-concatenation | statement | logical-operators | list-operation | thread-safe-data-structures-(queue.queue) | multiple-inheritance | method-overloading | set | filter | class-decorators | string-methods | reading-and-writing-files | pseudocode | choice | floats | using-the-threading-module | boolean | mapping-function | logical-operation | loops | error-handling | floating-point-precision | exception-handling | staticmethod | match | introduction-to-multiprocessing | membership-operators-(in,-not-in) | function-and-scope | identity-operators-(is,-is-not) | string-manipulation | filtering-and-indexing | turtle | python-history | else | logical-operator | random-function | expand-tab | while-loop | int | operand | indexing | loop | iterators | goto-function | numeric | package-management | list-vs-tuple | keyword | version | file-handling | operator | oop | encoding | lambda | using-assertions-(assertequal,-assertraises) | working-with-dates-and-times | lambda-function | else-statement | input-function | exception-handling | functional-programming | working-with-temporary-files-using-tempfile | immutability | higher-order-function | functional-programming | exception | walking-through-directories-using-os.walk() | matplotlib | string | working-with-binary-files-(rb,-wb) | virtual-environment | global | while-else-loop | id-function | variable | tuple-methods | min-function | list | import-method | string-slicing | interpreter | implementation | lambdas | list,-set,-and-dictionary-comprehensions | raise | input | while-and-for-loop | indexing:-loc-vs-iloc | intering | zip | python-module | name-mangling | string-slicing | string-formatting | list-join | mathematical-function ...