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