Level 1 : What will be the output of the following Python code?


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

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