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