Level 1 : What is the output?


def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = b, a + b

g = fibonacci(5)
print(list(g))

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