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