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