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