Level 9 : what is the output?


def gen():
    yield 1
    yield 2
    yield 3

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

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