हिंदी

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

प्रश्न

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

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

विकल्प

  • 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
अभिकथन और तर्क
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×