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