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