Level 5 : What will be the output of the following code snippet?


def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

print(factorial(5))

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