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