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