Question:

Consider the statements given below and then choose the correct output from the given options:
myStr = "MISSISSIPPI"
print(myStr[:4] + "#" + myStr[-5:])
    

Show Hint

In Python, positive indices count from the start (0), while negative indices count from the end (-1). Use them effectively for slicing strings.
Updated On: Jan 21, 2025
  • MISSI#SIPPI
     

  • MISS#SIPPI
     

  • MISS#IPPIS
     

  • MISSI#IPPIS

Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

The slicing operations in the given code work as follows:
  • myStr[:4] extracts the first 4 characters, which are "MISS".
  • myStr[-5:] extracts the last 5 characters, which are "SIPPI".
  • These two substrings are concatenated with a "#" in between, resulting in "MISS#SIPPI".
Was this answer helpful?
0
0