+ 1
Replace Characters in a String
I have a string, "hello" but let's say the string is unknown. I want to replace every character in that string x amount of times. Can anyone help me to do that please, thank you.
10 Respuestas
+ 3
Kirill Vidov, can you please complete the mentioned sample by showing us the desired output? Thanks!
+ 2
Yeah, you can take a look at my code..
https://code.sololearn.com/cyQB56iRtg01/?ref=app
+ 1
As strings are immutable,we can not modify the existing string.
But we can achieve it by using loops ,another strings
+ 1
Blue!! I tried doing it with a for loop but if I have a string with duplicates it's only going to replace the duplicates and leave the rest ones
0
Oops, sorry but they are pretty similar
0
You can use python built in replace() function
0
You can try this:
text = 'hello oorld'
replace = list(text)
replace[6] = 'W'
''.join(replace)
0
can u give sample Input and desired output as example
0
str="hello"
print(str.replace("h","k"))
for n times , you may run a loop