Computer Science
Write the output of the following:
s = "Strings in Python"
print(s.capitalize())
print(s.title())
s6 = s.replace("in", "data type")
print(s6)
Python
Python String Manipulation
1 Like
Answer
Strings in python
Strings In Python
Strdata typegs data type Python
Working
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.
Answered By
3 Likes
Related Questions
Write the output of the following:
>>> x = "hello" >>> print(x[1:-2])
Write the output of the following:
string = "Hello Madam, I love Tutorials" substring = "Madam" if string.find(substring) != -1: print("Python found the substring!") else: print("Python did NOT find the substring!")
Find the output of the following:
word = 'work hard' result = word.find('work') print("Substring, 'work', found at index:", result) result = word.find('har') print("Substring, 'har ' ,found at index:", result) if (word.find('pawan') != -1): print("Contains given substring ") else: print("Doesn't contain given substring")
Consider the following string mySubject:
mySubject = "Computer Science"
What will be the output of the following string operations?
(i) print (mySubject [0:len(mySubject)])
(ii) print (mySubject[-7:-1])
(iii) print (mySubject[::2])
(iv) print (mySubject [len (mySubject) -1])
(v) print (2*mySubject)
(vi) print (mySubject[::-2])
(vii) print (mySubject[:3] + mySubject[3:])
(viii) print (mySubject.swapcase() )
(ix) print (mySubject.startswith('Comp') )
(x) print (mySubject.isalpha() )