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