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