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