Level 1 : What is the output of the following code?


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

print(func(1))
print(func(2))

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