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