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