Test Index
Python Revision Tour
© examsnet.com
Question : 57 of 102
Marks:
+1,
-0
Consider the statements given below and then choose the correct output from the given options :
myStr="MISSISSIPPI"print(myStr[:4]+"#"+myStr[-5:])
[CBSE 2024 Set 4]
Solution:
Concept:
s[:n] gives the first n characters; s[-n:] gives the last n characters.Solution:myStr = "MISSISSIPPI" (11 characters, index 0 to 10)myStr[:4] = index 0 to 3 = MISSmyStr[-5:] = last 5 characters = SIPPIJoined with #: MISS#SIPPIKey point: The stop index is not included, so [:4] gives 4 characters, not 5.Answer:Option B (MISS#SIPPI)© examsnet.com
Go to Question: