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