Level 10 : What will the following code snippet produce?


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

list1 = func(10)
list2 = func(20, [])
list3 = func(30)
print(list1, list2, list3)

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