Home > Enterprise >  How can i make user enter "string" and enter (index) and remove this (index) from "st
How can i make user enter "string" and enter (index) and remove this (index) from "st

Time:11-04


Text = input(">> Please, Enter The Text: ")
index_X = input(">> Please, Enter The index_X which you want to remove from 'Text': ")
print(Text.remove(index_X))

i tried to use replace method but i think there is another way

CodePudding user response:

You could take the piece of the string prior to the index and then the piece of the string after the index and put them together.

Text = input(">> Please, Enter The Text: ")
index_X = int(input(">> Please, Enter The index_X which you want to remove from 'Text': ")) #convert to int
new_text = Text[:index_X]   Text[index_X 1:]
print(new_text)
  • Related