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