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