Level 4 : What is the output of the following code?


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

    def __iter__(self):
        return self

    def __next__(self):
        if self.current < self.end:
            val = self.current
            self.current += 1
            return val * 2
        else:
            raise StopIteration

it = SimpleIterator(0, 3)
output_list = []
for num in it:
    output_list.append(num)
print(output_list)

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