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