Level 1 : What is the output of the following code?


def filter_even(nums):
    for num in nums:
        if num % 2 == 0:
            yield num

g = filter_even(range(10))
print(next(g), next(g), next(g))
print(list(g))

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