ValueError: Cannot specify ',' with 's'.

0

Problem

This error is raised when you pass a string to the format() function

The ValueError exception occurs when you attempt to pass a variable of type string to format().

>>> pop="4534305483"
>>> type(pop)
<class 'str'>
>>> print(format(pop,","))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Cannot specify ',' with 's'.
>>>

Solution

The format() function can be used to format a long number with commas

>>> pop = 4534305483
>>> print(pop)
4534305483
>>> print(format(pop,","))
4,534,305,483

This error can be avoided by first calling int() on your variable to cast it to an integer

>>> print(format(int(pop),","))
4,534,305,483

More Information