Level 10 : What is the output of the following code?


def func(val, data=[]):
    data.append(val)
    return data

print(func(1))
print(func(2))

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