+ 6
How can I delete a character from a string?
9 Respuestas
+ 9
U can use PYTHONs replace method like this...
//Python3
STRING = "hello world"
STRING.replace("h", "")
print(STRING)
//Output
ello world
+ 5
print("text here".replace("here", ""))
Outputs: "text "
+ 4
Original string won't change ,so you need to create a new variable to store the new string returned by replace method
STRING=STRING.replace("h","")
+ 4
string are immutable, which means you cant change it’s content directly.
you can work with the string as a list to delete the charecter using a for loop and remove() and then join them together using ‘’.joiin().
+ 4
Steve Sajeev I think this method wont work properly with duplicates.
+ 4
Thanks a ton
+ 4
Abdulaziz_albusaidi
Yes are right, as long as I am correct, it would become little advanced.
Thats why I didnt Include
I dont know anyother methods
+ 1
s = "corre1ct"
s = s[:5] + s[6:]
print(s)
+ 1
String is immutable