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