Level 9 : What will the following code print?


def func(a, b=[]):
    b.append(a)
    return b

print(func(1))
print(func(2, []))
print(func(3))

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