Level 5 : What will the following code output?


def func(x, y=[]):
    y.append(x)
    return y

print(func(1))
print(func(2, []))
print(func(3))

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