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