Level 1 : What will the following code print?


def func(a, b=[]):
    b.append(a)
    return b

print(func(1))
print(func(2, []))
print(func(3))

Author: VenuEmmela | Tags: mutable | 1736+ Python FAQs | Share
boolean | lambda | overflow | assert | integer | list | import-method | built-in-function | namespace | error | set | sys | encoding | loop | binary | identity-operator | data_structure | turtle | python-django | command-line-parsing | heap-memory | filter | precedence-and-associativity | memory-management | pandas | objects | filter-function | precedence | asyncio-module | debugging | else-statement | classes | min-function | built-in-function | descriptors | init | docstring | scientific-notation | global-keyword | stack | type-conversion | version | class | def | default-mutable-argument | datetime | arithmetic-expression | magic-method | exponentiation | for | counter-function | id-function | datatype | numeric | logical-operator | loop-control | static-method | file | encapsulation | while-and-for-loop | int | escape-operator | generator | feature | string-concatenation | conversion | global | compute | input-function | python-history | matplotlib | dictionaries | syntaxerror | functional-programming | matrix | syntax-error | regex | data-structures | boolean-and-non-boolean | generators | sorted | arithmetic-operation | condition | sorting | destructor | fabs-function | enumerate() | list-indexing | multiple-inheritance | data-type | exception-handling | library | string-formatting | python | binary-operation | class-and-instance-variable | zip | choice | sum() | type_conversion | control-flow | staticmethod | bitwise-operator | built-in | file-handling | input-function | postfix | numpy | nested-loop | conditional-statement | oop | goto-function | global-variable | data-structure | pickling-&-unpickling | invalid-list | call | conditional-statement | control-flow | dicts | object-attribute | tuple-unpacking | error-handling | list-comprehension | gil | collection | set-operation | iterator | operator-or | string-manipulation | operator | input | data-type | rollback | join | namedtuple | async | append | return-statement | max-min | lists | keyword | threading | indentation | with-statement | bitwise-operator | iterable | oops | list-comprehension | application | string-method | global-variable | operations | operator-overloading | pseudocode | array | package-management | recursion | complex-number | swapping | parameter | inheritance | random-function | update | data-structure | exception | match | mathematical-function | basic | generators-in-python | head-and-tail | functions | syntax-error | version-check | virtual-environment | operator-and | comprehension | attribute | factorial-function | installation | multithreading | class-and-object | complex | formal-and-actual-parameter | mathematics | raise | min-max-function | map-function | format | memory | file-handling | collections | dictionary | yield | list-mutation | interpreter | loops | slice | file_handling | matrix-list-comprehension | expand-tab | typeerror | recurssion | counter | string-iteration | round-function | pep | python-repl | string-slicing | __all__-attribute | operators | class-and-inheritance | mysql | access-modifier | type-conversion | python_version | inherit | range | immutability | tuple | list-join | list-operation | odd-number | asyncio | statement | bitwise | name-mangling | method | higher-order-function | syntax | frozenset | string | while-else-loop | __future__ | control-statement | round | list-method | zfill-function | mapping-function | indexing | split | function-and-scope | module | math-copysign | print | function-argument | string-method | center | polymorphism | math | decorator | list-vs-tuple | exception-handling | lambdas | comment | methods | string-slicing | zip-function | while-loop | expression | slicing | operand | variable | touples | benefit | print-statement | mutable | identity-operator | list-slicing | python-module | shallow-copy | design-principle | virtual-environment | immutable-data-type | assignment-operator | implementation | copy | sum-function | logical-operation | thread | regular-expression | lambda-function | floating-point-precision | decimal | identifier | multiprocessing | context-manager | sys-module | deep-copy | string-formatting | __init_subclass__ | constructor | comparison | random | function | software-design | logical-operator ...