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