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