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