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