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