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