Level 9 : What is the output?


def add_to(num, target=[]):
    target.append(num)
    return target

print(add_to(1))
print(add_to(2))
print(add_to(3, []))
print(add_to(4))

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