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