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