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