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