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