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