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