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


def func(a, L=[]):
    L.append(a)
    return L

print(func(1))
print(func(2))
print(func(3, []))
print(func(4))

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