Question 1 of 6intermediate🔧 ApplyShort Answer5 marks

Consider the following string mySubject: mySubject = "Computer Science" What will be the output of the following string operations:

(i)

print(mySubject[0:len(mySubject)])

Answer

Computer Science

(ii)

print(mySubject[-7:-1])

Answer

Scienc

(iii)

print(mySubject[::2])

Answer

Cmue cec

(iv)

print(mySubject[len(mySubject)-1])

Answer

e

(v)

print(2*mySubject)

Answer

Computer ScienceComputer Science

(vi)

print(mySubject[::-2])

Answer

eniSrtpo

(vii)

print(mySubject[:3] + mySubject[3:])

Answer

Computer Science

(viii)

print(mySubject.swapcase())

Answer

cOMPUTER sCIENCE

(ix)

print(mySubject.startswith('Comp'))

Answer

True

(x)

print(mySubject.isalpha())

Answer

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.