Level 10 : What will be the output of the following code?


def outer():
    x = 5
    def inner():
        nonlocal x
        x = 10
    inner()
    return x

print(outer())

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