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