Level 5 : What is the output for the below code?


def foo():
    try:
        raise ValueError("An error")
    except ValueError:
        return "Caught"
    finally:
        return "Finally"

print(foo())

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