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