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