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