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