Level 1 : What happens in this generator?


def test():
    yield 1
    return 2
    yield 3

g = test()
print(next(g))
print(next(g))

Author: SandhyaR | Tags: iterator | 1736+ Python FAQs | Share
default-mutable-argument | data-structure | syntax-error | sum() | context-manager | docstring | pandas | pep | iterable | encoding | exception-handling | counter-function | asyncio | escape-operator | data-structure | global-variable | memory-management | module | match | list-slicing | asyncio-module | overflow | binary | filter-function | raise | random | attribute | pseudocode | copy | multiprocessing | expression | data_structure | touples | decimal | update | type-conversion | namespace | software-design | collection | lists | parameter | multithreading | loop | print | binary-operation | collections | precedence | virtual-environment | type_conversion | basic | python-repl | comprehension | identifier | debugging | design-principle | expand-tab | generator | string-concatenation | matrix | class | function-argument | library | else-statement | multiple-inheritance | odd-number | heap-memory | input-function | string-manipulation | method | compute | id-function | append | operator | mathematics | functional-programming | random-function | formal-and-actual-parameter | decorator | min-max-function | data-type | global-variable | min-function | int | loops | call | boolean-and-non-boolean | higher-order-function | object-attribute | bitwise-operator | input-function | version | mysql | __all__-attribute | choice | exception-handling | objects | lambda | async | python-django | classes | list-mutation | arithmetic-operation | floating-point-precision | goto-function | control-flow | interpreter | syntax | sorting | comment | fabs-function | condition | center | generators | integer | import-method | function | sys | string-method | namedtuple | identity-operator | bitwise-operator | set | lambda-function | string-formatting | python-history | string | array | regular-expression | init | round | assignment-operator | operator-and | list-comprehension | matrix-list-comprehension | pickling-&-unpickling | loop-control | recurssion | mathematical-function | generators-in-python | sorted | __init_subclass__ | round-function | list-method | file_handling | list | counter | control-flow | list-comprehension | built-in-function | input | immutability | mutable | print-statement | shallow-copy | syntax-error | indentation | list-operation | arithmetic-expression | error | static-method | built-in-function | comparison | operators | zip-function | dictionary | constructor | class-and-inheritance | data-structures | math | format | variable | logical-operation | math-copysign | virtual-environment | mapping-function | assert | command-line-parsing | boolean | regex | oop | set-operation | yield | lambdas | function-and-scope | file-handling | complex | with-statement | stack | split | zfill-function | string-iteration | access-modifier | return-statement | conditional-statement | error-handling | list-join | descriptors | global | sum-function | factorial-function | tuple-unpacking | inheritance | datatype | scientific-notation | type-conversion | syntaxerror | version-check | numeric | staticmethod | installation | logical-operator | dictionaries | string-method | keyword | immutable-data-type | swapping | nested-loop | python | indexing | sys-module | data-type | datetime | operand | statement | memory | slice | global-keyword | rollback | destructor | while-else-loop | invalid-list | map-function | operator-or | frozenset | application | identity-operator | deep-copy | list-vs-tuple | turtle | filter | list-indexing | numpy | name-mangling | max-min | exponentiation | operator-overloading | oops | enumerate() | exception | operations | conversion | string-slicing | control-statement | head-and-tail | built-in | threading | range | precedence-and-associativity | conditional-statement | python_version | bitwise | zip | package-management | recursion | string-formatting | encapsulation | for | tuple | class-and-object | join | def | while-and-for-loop | file-handling | gil | magic-method | functions | matplotlib | file | benefit | feature | slicing | methods | string-slicing | postfix | iterator | thread | typeerror | inherit | __future__ | python-module | dicts | complex-number | class-and-instance-variable | while-loop | polymorphism | implementation | logical-operator ...