Computer Science
Select the correct output of the following string operators.
str1='One'
print(str1[:3] + 'Two' + str1[-3:])
- OneOneTwo
- TwoOneOne
- OneTwoOne
- 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
1 Like
Related Questions
Which of the following functions will return the first three characters of a string named 's'?
- s[3:]
- s[:3]
- s[-3:]
- s[:-3]
Observe the given code and select the appropriate output.
Tuple given: tup1 = (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of: print(tup1[3:7:2])
- (40, 50, 60, 70, 80)
- (40, 50, 60, 70)
- (40, 60)
- Error
When a list is contained in another list as a member-element, it is called …………… .
- Nested tuple
- Nested list
- Array
- List
The …………… method removes the last entered element from the dictionary.
- pop()
- remove()
- popitem()
- del