Level 1 : What is the output?


def even_numbers(limit):
    for i in range(limit):
        if i % 2 == 0:
            yield i

g = even_numbers(6)
print(next(g))
print(next(g))
print(next(g))
print(next(g))

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