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