+ 1
Replace characters in a string without loops
I tried using slicing but didn't succeed https://code.sololearn.com/cn3THw67hQap/?ref=app
2 ответов
+ 1
Use regular expressions.
Minimal use:
if string in your code contains a date and you just want to replace "-" or "/" or anything else other than numbers
import re
num = re.sub(r'\D', "", string)
print("Phone Num : ", num)
+ 1
I think you want to do something like this:
x='00001'
x=x.replace('0','2')
print(x)
Output--> 22221