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