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