这是我的代码:
str1 = "Hello How are you dude?"
print("\nInitial String :" + str1)
n = int(input("Enter index number to remove character from above string :"))
if n <= len(str1):
first_part = str1[:n]
second_part = str1[n+1:]
final_string = first_part + second_part
print("Result String :", final_string)
else:
print("Your Entered Number is out of the range..!!")
他是我的输出:
Initial String :Hello How are you dude?
Enter index number to remove character from above string :23
Result String : Hello How are you dude?
当我输入一个字符串的总长度 + 1 时,它给我的输出与我的原始字符串相同。您也可以在我提到输出的代码中看到。它将如何发生?谁能解释一下?