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