Level 9 : What is the output for the below code?


def f(x, y=[]):
    y.append(x)
    return y

print(f(1))
print(f(2))

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