Level 5 : What happens here?


def f(a, b=[]):
    b.append(a)
    return b

print(f(1))
print(f(2))

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