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