1

I have this string

s = "1,395,54"

I would like to remove the first comma to obtain the following string:

s = "1395,54"

What is the most efficient way to solve this simple problem?

2 Answers 2

4

You can use str.replace, it takes a third argument which specifies the number of occurrences to replace.

>>> your_str = "1,395,54"
>>> your_str.replace(",", "", 1)
'1395,54'
Sign up to request clarification or add additional context in comments.

Comments

0

By slicing the string. The find method return the index of the first match

s = "1,395,54"

index = s.find(',')
print(s[:index] + s[index+1:])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.