If you only need to add comma as thousand separator and are using Python version 3.6 or greater:
print(f"{number:,g}")
This uses the formatted string literals style. The item in braces {0}
is the object to be formatted as a string. The colon :
states that output should be modified. The comma ,
states that a comma should be used as thousands separator and g
is for general number. [1]
With older Python 3 versions, without the f-strings:
print("{0:,g}".format(number))
This uses the format-method of the str-objects [2]. The item in braces {0}
is a place holder in string, the colon :
says that stuff should be modified. The comma ,
states that a comma should be used as thousands separator and g
is for general number [3]. The format
-method of the string object is then called and the variable number
is passed as an argument.
The 68,471,24,3 seems a bit odd to me. Is it just a typo?
Formatted string literals
Python 3 str.format()
Python 3 Format String Syntax