English

Assertion (A): [1,2,3]+‘123’ is an invalid expression in Python. Reason (R): In Python, a list cannot be concatenated with a string. - Computer Science (Python)

Advertisements
Advertisements

Question

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

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

Options

  • Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).

  • Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A).

  • Assertion (A) is true, but Reason (R) is false.

  • Assertion (A) is false, but Reason (R) is true.

MCQ
Assertion and Reasoning
Advertisements

Solution

Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).

Explanation:

In Python, the + operator performs concatenation only when both operands are of the same data type. Since [1, 2, 3] is a List and '123' is a String, attempting to add them results in a TypeError, making the expression invalid as stated.

shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×