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