Q20
1 markSection A

Assertion (A) : [1,2,3]+'123' is an invalid expression in Python.

Reason (R) : In Python, a list cannot be concatenated with a string.

Python Revision Tour
Type Compatibility in Python Concatenation

Options

(A)Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).
(B)Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A).
(C)Assertion (A) is true, but Reason (R) is false.
(D)Assertion (A) is false, but Reason (R) is true.
Official Answer

Correct option: (A) — Both Assertion (A) and Reason (R) are true, and Reason (R) is the correct explanation of Assertion (A).

type compatibilitylist concatenationstring concatenationTypeError+ operatorsequence typesPython data types

Marking Scheme

  • 11 mark for selecting option (A); no partial marks in Assertion-Reason questions.

Hint

Try concatenating a list and a string mentally with '+' and recall Python's rule that '+' needs matching sequence types on both sides.

Quick Oral Answer

The expression [1,2,3]+'123' is invalid because Python's '+' operator requires both operands to be the same sequence type — you cannot directly concatenate a list with a string.

Analysis & Explanation

This question tests the rule that the '+' operator, when used for concatenation, requires BOTH operands to be of the SAME sequence type.


Checking Assertion (A)

  • [1,2,3] is a list and '123' is a string — two different sequence types.
  • Attempting [1,2,3]+'123' raises TypeError: can only concatenate list (not "str") to list.
  • So the expression IS invalid, making Assertion (A) true.

Checking Reason (R)

  • Python's '+' operator for sequences is type-strict: list+list works, str+str works, but list+str does not.
  • Reason (R) states exactly this rule, so it is also true.

Linking A and R

  • Reason (R) is precisely WHY the expression in Assertion (A) fails — the general rule (R) directly explains the specific invalid case (A).
  • Hence option (A) is correct: both statements true, and R correctly explains A.

Common Mistakes

  1. 1Believing Python automatically converts the string to a list of characters or the list to a string before concatenation — Python does NOT perform such implicit conversions with '+'.
  2. 2Selecting option (B), mistakenly thinking Reason (R) is a true but unrelated statement rather than recognising it directly explains Assertion (A).

Interesting Facts

The exact Python error for this case is `TypeError: can only concatenate list (not "str") to list` — a very commonly seen runtime error among beginners.

To concatenate a list and characters of a string, one must explicitly convert, e.g. `[1,2,3] + list('123')`, which converts the string into `['1','2','3']` first, making both operands lists.

Spotted a mistake or something unclear?

Tell us — we fix reported answers fast.

Frequently Asked Questions

Why does [1,2,3]+'123' raise an error in Python?

Because Python's '+' operator for sequences requires both operands to be of the same type; here a list and a string are being concatenated, which is not permitted.

How can you correctly combine a list and characters of a string in Python?

Convert the string to a list first using list(), e.g. [1,2,3] + list('123'), which produces [1, 2, 3, '1', '2', '3'].