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.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- 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
STR = "RGBCOLOR" colors = list(STR)How do we delete 'B' in given List colors?
- del colors[2]
- colors.remove("B")
- colors.pop(2)
- All of these
Which of the following will give "Simon" as output?
str1 = "Hari,Simon,Vinod"- print(str1[-7:-12])
- print(str1[-11:-7])
- print(str1[-11:-6])
- print(str1[-7:-11])
Assertion (A): print('INDIA'.capitalize())
This command on execution shall display the output as 'India'.Reasoning (R): The capitalize() method returns a string where the first character is uppercase and the rest is lower case.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): The process of repeating a set of elements in a string is termed as replication.
Reasoning (R): Repetition allows us to repeat the given string using (*) operator along with a number that specifies the number of replications.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.