Level 1 : Infinite arithmetic sequence.


def arithmetic_seq(start, step):
    while True:
        yield start
        start += step

gen = arithmetic_seq(1, 3)
for _ in range(5):
    print(next(gen), end=" ")

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