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