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