CBSE Class 11 Computer Science Question 9 of 19

Strings in Python — Question 6

Back to all questions
6
Question

Question 5(b)

Write the output of the following:

s = "Strings in Python"
print(s.capitalize())
print(s.title())
s6 = s.replace("in", "data type")
print(s6)
Answer
Output
Strings in python
Strings In Python
Strdata typegs data type Python
Explanation

The s.capitalize() method capitalizes the first letter of the string and converts the rest to lowercase, resulting in "Strings in python". The s.title() method capitalizes the first letter of each word, producing "Strings In Python". The s.replace("in", "data type") method replaces occurrences of "in" with "data type", giving "Strdata typegs data type Python" as output.