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