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