Recommended Free Tools
Use str.translate() with a table built by str.maketrans() to swap every comma and period at once. For example, "1,234.56" becomes "1.234,56", while all other characters stay unchanged.
Swap commas and periods simultaneously
Pair the two original characters with their replacements in one translation table:
s = "1,234.56"
swapped = s.translate(str.maketrans(",.", ".,"))
print(swapped) # 1.234,56
str.maketrans() maps characters by position: the first character in the source string maps to the first in the destination, and the second maps to the second. The strings must have equal lengths. Then str.translate() applies that mapping to each character and returns a new string; it does not modify the original. See the Python 3.14.8 built-in types reference.
Change only one character with replace()
If you want to change every comma to a period but leave existing periods alone, use replace():
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
s = "1,234.56"
result = s.replace(",", ".")
print(result) # 1.234.56
With no count argument, replace() changes every matching occurrence and returns a new string. To replace only the first two commas, for example, pass a count: s.replace(",", ".", 2). This is a one-way replacement, not a swap.
Why chained replacements do not swap safely
Calling replace() twice can change characters inserted by the first call. For instance:
Rank #2
s = "1,234.56"
result = s.replace(",", ".").replace(".", ",")
print(result) # 1,234,56
The second call converts both the original period and the period inserted for the comma. Use the translation table for a simultaneous exchange, rather than relying on a temporary placeholder.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When the string represents a number
A character swap is a literal text operation, not a numeric parser or locale conversion. First establish what the input means: which mark is the decimal separator, which is a grouping separator, and whether the text follows a known convention. A blind swap can change the apparent value or create text that a decimal parser will not accept.
Python’s documented Decimal string syntax uses a period in the decimal part. The decimal module’s formatting recipe lets you configure the decimal point and grouping separator separately; formatting choices should be made for the intended output rather than by blindly exchanging characters. See the Python 3.14.8 decimal module reference.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




