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