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