Skip to content
Question 51 of 97

Q.Q. 17 and 18 are ASSERTION (A) and REASONING (R) based questions. Mark the correct choice as (A) Both (A) and (R) are true and (R) is the correct explanation for (A) (B) Both (A) and (R) are true and (R) is not the correct explanation for (A) (C) (A) is true but (R) is false (D) (A) is false but (R) is true 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.

Sikkim CbseCBSE Class XII Board 2024MCQ· 1mImportance★★★★★
53% · 51/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The assertion is true — calling .sort() on a string raises an error — and the reason correctly explains why: strings have no sort() method. Both are true, and (R) is the correct explanation for (A). The answer is (A).

The concept: methods belong to types

In Python, every object has a specific type — integers, lists, strings, etc. Each type comes with its own set of methods (functions that belong to that type). For example, lists have .append(), .pop(), and .sort(). Strings have .upper(), .lower(), .split(), and so on.

The key question here is: does the string type have a .sort() method? If not, calling it will produce an AttributeError — Python's way of saying "this object doesn't know how to do that."

Step-by-step reasoning

  1. What does "HELLO".sort() actually try to do?

    The expression "HELLO".sort() attempts to call a method named sort on the string object "HELLO". Python will look for a method called sort in the string class's definition.

  2. Does the string class have a sort method?

    No. Strings in Python are immutable sequences of characters. They support methods like .upper(), .lower(), .find(), .replace(), and .split(), but not .sort(). The sort() method exists only on mutable sequence types like lists.

    Watch out

    A common mistake is to confuse strings with lists. Lists have .sort() because they are mutable — you can rearrange their elements in place. Strings are immutable; you cannot change their characters in place, so sorting a string directly makes no sense.

  3. What happens when you run "HELLO".sort()?

    Python raises an AttributeError with a message like:

    'str' object has no attribute 'sort' …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.