Level 1 : What will be the output of the following Python code?


def a(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return a(n-1)+a(n-2)
for i in range(0,4):
    print(a(i),end=" ")

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