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