Computer Science

Select the correct output of the following string operators.

str1='One'
print(str1[:3] + 'Two' + str1[-3:])
  1. OneOneTwo
  2. TwoOneOne
  3. OneTwoOne
  4. Error

Python String Manipulation

3 Likes

Answer

OneTwoOne

Reason — The code uses str1[:3] to extract the first three characters of str1, which are 'One', and str1[-3:] to extract the last three characters, which are also 'One'. It then concatenates these with 'Two', resulting in 'OneTwoOne', which is printed.

Answered By

3 Likes


Related Questions