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