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