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