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