Computer Science
Write the Python statement and the output for the following:
(a) Find the third occurrence of 'e' in 'sequence'.
(b) Change the case of each letter in string 'FuNcTioN'.
(c) Whether 'Z' exists in string 'School' or not.
Python String Manipulation
1 Like
Answer
(a)
s = 'sequence'
index = s.find('e', s.find('e', s.find('e') + 1) + 1)
print(index)
Output
7
(b)
s = 'FuNcTioN'
print(s.swapcase())
Output
fUnCtIOn
(c)
s = 'School'
print('Z' in s)
Output
False
Answered By
1 Like
Related Questions
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() )
Consider the string str1 = "Global Warming".
Write statements in Python to implement the following:
(a) To display the last four characters.
(b) To replace all the occurrences of letter 'a' in the string with "*".
What will be the output of the following code?
Text = "Mind@Work!" ln = len(Text) nText = "" for i in range(0, ln): if Text[i].isupper(): nText = nText + Text[i].lower() elif Text[i].isalpha(): nText = nText + Text[i].upper() else: nText = nText + 'A' print(nText)