Level 1 : What will be the output of the following Python code?


def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))

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