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