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