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