Level 1 : What is the output of the following code?


def sample():
   try:
        return 6
   finally:
        return 5
k = sample()
print(k)

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