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