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