Question:

Assertion (A): The expression "HELLO".sort() in Python will give an error. 
Reason (R): sort() does not exist as a method/function for strings in Python. 
Mark the correct choice: 
 

Show Hint

Use sorted()} to sort characters in a string after converting it to a list using list()}.
Updated On: Jan 21, 2025
  • Both (A) and (R) are true and (R) is the correct explanation for (A).
  • Both (A) and (R) are true and (R) is not the correct explanation for (A).
  • (A) is true but (R) is false.
  • (A) is false but (R) is true.
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

The sort() method is not defined for string objects in Python. It is used for lists, not strings. Therefore, trying to use sort() on a string object like "HELLO" results in an AttributeError, making both the assertion and reasoning true, with (R) correctly explaining (A).

Was this answer helpful?
0
0