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