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