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