Advertisements
Advertisements
Question
Identify the output of the following code snippet:
8 = “the Truth”
print(s.capitalize())
Options
The truth
THE TRUTH
The Truth
the Truth
MCQ
Advertisements
Solution
The truth
Explanation:
The capitalize() A method in Python transforms a string by making the very first character uppercase and converting all other characters to lowercase.
- In the original string
s = “the Truth”, the first letter is‘t’. capitalize()changes‘t’to‘T’.- It also changes the existing uppercase
‘T’in "Truth" to a lowercase‘t’. - Therefore, the final output is
“The truth”
shaalaa.com
Is there an error in this question or solution?
