Level 10 : What will be the output of the following Python code?


def foo():
    try:
        return 1
    finally:
        return 2
k = foo()
print(k)

Author: HareramG | Tags: exception-handling | 1736+ Python FAQs | Share
debugging | immutability | built-in-function | virtual-environment | string | while-else-loop | indentation | polymorphism | round-function | while-and-for-loop | mathematical-function | __all__-attribute | def | set | integer | function-and-scope | method | join | list-vs-tuple | command-line-parsing | arithmetic-operation | exception-handling | numeric | memory-management | datatype | namespace | string-iteration | global | conditional-statement | class-and-inheritance | id-function | import-method | feature | regular-expression | formal-and-actual-parameter | assert | choice | inherit | compute | sys | precedence-and-associativity | while-loop | turtle | counter-function | docstring | overflow | file_handling | statement | string-concatenation | heap-memory | oop | parameter | namedtuple | python | virtual-environment | string-formatting | objects | zip-function | init | loop | staticmethod | logical-operation | data-type | swapping | __init_subclass__ | rollback | type_conversion | exception-handling | min-function | math-copysign | comment | slicing | identity-operator | type-conversion | operator-or | classes | decimal | dictionary | descriptors | scientific-notation | encoding | lambda | mathematics | counter | array | built-in-function | global-keyword | package-management | data-structure | generator | string-formatting | conversion | split | else-statement | thread | python-module | stack | class-and-instance-variable | filter-function | numpy | data-structures | odd-number | constructor | data-structure | postfix | syntaxerror | gil | conditional-statement | lambdas | collection | string-manipulation | matplotlib | variable | filter | logical-operator | multiprocessing | min-max-function | version | threading | memory | int | file-handling | random | pandas | class | lists | type-conversion | exponentiation | magic-method | list-indexing | file-handling | async | default-mutable-argument | range | implementation | center | goto-function | copy | input-function | matrix | dictionaries | python-django | list | tuple | destructor | immutable-data-type | datetime | error-handling | basic | function | boolean-and-non-boolean | functions | dicts | sorted | error | list-comprehension | precedence | operand | identity-operator | string-slicing | asyncio-module | asyncio | data_structure | round | map-function | comprehension | mutable | shallow-copy | logical-operator | list-slicing | list-operation | boolean | regex | file | encapsulation | generators | software-design | update | head-and-tail | access-modifier | slice | global-variable | list-mutation | loop-control | arithmetic-expression | inheritance | static-method | lambda-function | input | object-attribute | recurssion | invalid-list | sorting | max-min | sum() | factorial-function | sys-module | tuple-unpacking | call | operator-overloading | list-method | syntax-error | condition | iterable | control-statement | mysql | mapping-function | comparison | attribute | operations | zfill-function | list-join | keyword | operator-and | binary | escape-operator | complex | operators | version-check | indexing | typeerror | matrix-list-comprehension | interpreter | for | binary-operation | append | library | string-slicing | exception | pep | deep-copy | random-function | string-method | name-mangling | string-method | generators-in-python | syntax-error | operator | python-history | decorator | touples | bitwise | control-flow | python-repl | match | expand-tab | recursion | fabs-function | pickling-&-unpickling | control-flow | enumerate() | collections | function-argument | zip | bitwise-operator | complex-number | bitwise-operator | frozenset | higher-order-function | input-function | built-in | format | print-statement | return-statement | python_version | nested-loop | design-principle | context-manager | installation | assignment-operator | oops | yield | identifier | methods | set-operation | with-statement | loops | multithreading | __future__ | expression | print | sum-function | raise | benefit | class-and-object | data-type | global-variable | functional-programming | math | multiple-inheritance | floating-point-precision | list-comprehension | application | module | iterator | pseudocode | syntax ...