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