Level 1 : What will be the output of the following code?


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

    def __iter__(self):
        return self

    def __next__(self):
        if self.current >= self.end:
            raise StopIteration
        self.current += 1
        return self.current - 1

c = Counter(1, 4)
print(list(c))

Author: SandhyaR | Tags: iterator | 1736+ Python FAQs | Share
list | list-comprehension | classes | version | objects | attribute | error | bitwise-operator | range | datatype | identity-operator | map-function | fabs-function | bitwise | assert | keyword | collections | syntaxerror | bitwise-operator | zip | feature | enumerate() | random | expand-tab | escape-operator | sum-function | set | datetime | file | operator-overloading | while-and-for-loop | input-function | regular-expression | class | indentation | mutable | error-handling | boolean-and-non-boolean | oops | function-and-scope | iterable | memory-management | deep-copy | generators-in-python | name-mangling | round | choice | iterator | typeerror | inherit | for | string-method | functions | oop | data-type | boolean | call | control-flow | multithreading | generators | overflow | recursion | copy | namedtuple | pickling-&-unpickling | comment | file_handling | matrix-list-comprehension | zip-function | filter | exception-handling | heap-memory | control-statement | data-structure | syntax-error | functional-programming | pep | basic | binary-operation | format | interpreter | nested-loop | loop | list-comprehension | random-function | context-manager | threading | lambdas | asyncio-module | global-variable | with-statement | access-modifier | operations | compute | precedence-and-associativity | python | complex-number | data-structure | python-repl | expression | rollback | operand | id-function | odd-number | slicing | polymorphism | list-operation | tuple-unpacking | class-and-inheritance | function | encoding | join | mathematics | collection | list-slicing | string | slice | counter | while-else-loop | lambda | application | lambda-function | destructor | raise | global-keyword | constructor | precedence | thread | filter-function | zfill-function | stack | integer | array | multiprocessing | touples | methods | generator | assignment-operator | design-principle | docstring | comparison | scientific-notation | import-method | recurssion | software-design | multiple-inheritance | built-in | min-function | string-slicing | complex | loop-control | class-and-object | dictionaries | list-mutation | append | numpy | package-management | round-function | namespace | string-concatenation | staticmethod | invalid-list | virtual-environment | sum() | string-manipulation | decorator | python-django | arithmetic-operation | sys-module | print | head-and-tail | built-in-function | descriptors | set-operation | operator | regex | lists | statement | data-structures | gil | string-formatting | method | input | print-statement | dicts | identifier | type-conversion | matrix | syntax-error | indexing | max-min | encapsulation | immutable-data-type | conditional-statement | input-function | sys | virtual-environment | math-copysign | __future__ | list-vs-tuple | def | data_structure | formal-and-actual-parameter | installation | decimal | swapping | condition | return-statement | python-module | function-argument | python_version | class-and-instance-variable | __init_subclass__ | math | control-flow | benefit | sorting | string-slicing | tuple | __all__-attribute | while-loop | version-check | operators | factorial-function | list-indexing | min-max-function | mathematical-function | mapping-function | exponentiation | python-history | built-in-function | list-method | debugging | split | higher-order-function | yield | center | logical-operator | async | postfix | string-formatting | syntax | loops | conversion | floating-point-precision | numeric | magic-method | identity-operator | conditional-statement | implementation | default-mutable-argument | update | command-line-parsing | frozenset | parameter | exception-handling | sorted | operator-and | matplotlib | turtle | static-method | library | counter-function | global-variable | shallow-copy | file-handling | comprehension | list-join | dictionary | goto-function | object-attribute | immutability | data-type | operator-or | string-iteration | arithmetic-expression | global | pandas | else-statement | string-method | variable | file-handling | match | logical-operation | inheritance | type_conversion | binary | module | int | type-conversion | mysql | pseudocode | logical-operator | exception | asyncio | init | memory ...