Level 10 : What is the output for the below code?


def gen():
    yield 1
    yield 2

g = gen()
print(next(g), list(g))

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