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