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