Advertisements
Advertisements
Question
Consider the statements given below and then choose the correct output from the given options:
myStr="MISSISSIPPI"
print(myStr[:4]+"#"+myStr[−5:])
Options
MISSI#SIPPI
MISS#SIPPI
MISS#IPPIS
MISSI#IPPIS
MCQ
Solution
MISS#SIPPI
Explanation:
Mystr[:4] retrieves "MISS" characters from index 0 to 3, concatenated with "#". The mystr[−5:] slice returns characters from index −5 to the end, resulting in the string 'SIPPI'. In Python, indices range from 0 to n−1 (ahead) and −1...−n (reverse). The final string created is 'MISS#SIPPI'.
shaalaa.com
Is there an error in this question or solution?