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