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