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