Level 1 : Generating even numbers.


def even_numbers(n):
    for i in range(0, n, 2):
        yield i

gen = even_numbers(10)
print(list(gen))

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