Level 6 : What will happen?


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

    def __iter__(self):
        return self

    def __next__(self):
        if self.current < 0:
            raise StopIteration
        val = self.current
        self.current -= 2
        return val

cd = CountDown(5)
print(list(cd))
print(list(cd))

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