Level 1 : What will be the output of the following code?


def extendList(val, list=[]):
    list.append(val)
    return list

list1 = extendList(10)
list2 = extendList(123, [])
list3 = extendList('a')

print(list1)
print(list2)
print(list3)

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