KnowledgeBoat Logo
|

Computer Science

Assertion(A): S1 ='CoMPuter SciENce'
S1[0] = S1[0].lower()

The above code will generate error.

Reasoning(R): String is immutable by default. The contents of the string cannot be changed after it has been created.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python String Manipulation

1 Like

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
In Python, strings are immutable, meaning that once a string is created, its contents cannot be modified. The statement S1[0] = S1[0].lower() attempts to change the first character of the string S1 to lowercase, but since strings are immutable, this operation will result in an Error.

Answered By

1 Like


Related Questions