I have a string that represents a number which uses commas to separate thousands. How can I convert this to a number in python?
>>> int(\"1,000,000
Replace the commas with empty strings, and turn the resulting string into an int or a float.
int
float
>>> a = '1,000,000' >>> int(a.replace(',' , '')) 1000000 >>> float(a.replace(',' , '')) 1000000.0