Hello, I have a list of decimals that I converted to String, to be able to change the points for commas. But with "replace" it doesn't allow me to make the change, I'm doing it this way:
for i in range(len(UCL)): #UCL de corte
UCL[i].replace(".",",")
print(UCL[i])
The original UCL list is of the form:
['2.363636368', '2.17391304', '3.875', '2.282828286', '2.383838386', '2.616161618', '2.363636368', '4.85', '4.75', '2.282828289', '2.616161618', '0.666666666', '3.0', '3.272727272', '2.434343439', '0.666666666', '0.666666666', '2.538461538', '0.666666666', '3.875', '2.616161618', '2.393939396', '0.666666666', '0.666666666', '0.666666666', '0.666666666', '2.383838384']
My idea is to print the same thing but change the dots to commas inside each string of the UCL list.
The problem is that it
str
is immutable andreplace
therefore returns a copy of the string (it cannot modify the original string). You can create a new list using list compression with:If you prefer to use a
for
normal and modify the original list you should do:I assume you want to modify the list in addition to printing it. If you just wanted to print using commas, without modifying the original list, you could do (in Python 3):
Or for Python 2/Python3:
Jorge, in Python strings like many other objects are immutable, do this:
It will return this:
With this we confirm that it
s
is still worth "1.4". What needs to be done is to generate a new string by assigning:and now yes
In your example you should do the following:
I used this and if it worked for me:
(tudato.replace(".",',') or :)
after the replace you mention what you want to replace, after what you want to appear and the
or
means or change.
or:
for a,
It works for me: