Level 10 : What is the output?


def gen():
    try:
        yield 1
        yield 2
        yield 3
    except GeneratorExit:
        print("Generator closed")

g = gen()
print(next(g))
g.close()
print(next(g))

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