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