Consider the following string mySubject: mySubject = "Computer Science" What will be the output of the following string operations:
print(mySubject[0:len(mySubject)])
Computer Science
print(mySubject[-7:-1])
Scienc
print(mySubject[::2])
Cmue cec
print(mySubject[len(mySubject)-1])
e
print(2*mySubject)
Computer ScienceComputer Science
print(mySubject[::-2])
eniSrtpo
print(mySubject[:3] + mySubject[3:])
Computer Science
print(mySubject.swapcase())
cOMPUTER sCIENCE
print(mySubject.startswith('Comp'))
True
print(mySubject.isalpha())
False
Explanation
The string mySubject = 'Computer Science' has 16 characters (indices 0-15). Each operation uses different string concepts: (i) slicing from 0 to length returns the full string; (ii) negative indexing where -7='S' and -1='e'(exclusive) gives 'Scienc'; (iii) step 2 extracts even indices; (iv) last character accessed via length-1; (v) repetition operator duplicates string; (vi) negative step traverses backwards; (vii) concatenation rejoins split parts; (viii) swapcase inverts case; (ix) startswith checks prefix; (x) isalpha returns False due to space character.