Level 9 : What is the output?


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

print(outer())

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