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