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