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


def sample():
       try:
          print(4)
       finally:
           print(7)
sample()

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