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