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