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