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