Level 1 : What is the output?


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

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

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