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


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

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