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