Level 10 : what is the output for the below code?


def outer():
    x = 2
    def inner():
        nonlocal x
        x += 3
        return x
    return inner

f = outer()
print(f(), f())

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