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