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