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