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