Test Index
Python Revision Tour
© examsnet.com
Question : 60 of 102
Marks:
+1,
-0
Q. 17 and 18 are ASSERTION (A) and REASONING (R) based questions. Mark the correct choice as :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.[CBSE 2024 Set 4]
Solution:
Assertion (A): True.
"HELLO".sort() raises AttributeError: 'str' object has no attribute 'sort'.Reason (R): True. sort() is a list method. Strings are immutable and have no sort() method (sorted("HELLO") works and returns a list).Explanation:The error in A occurs exactly because strings do not have a sort() method, so R correctly explains A.Answer:Option A (Both (A) and (R) are true and (R) is the correct explanation for (A).)© examsnet.com
Go to Question: