s = "a-b-c-d" print(s.replace("-", "_")) # all print(s.replace("-", "_", 2)) # first two
replace all, or the first n