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