Level 9 : What will be the output of the following code?


x = 50
def func(x):
    print('x is', x)
    x = 2
    print('Changed local x to', x)
func(x)
print('x is now', x)

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