What is the purpose of dollar sign in this Python3 string formatting expression?

It has no special meaning. It just inserts a $ character:

>>> "(%d goals, $%d)" % (10, 42)
'(10 goals, $42)'

Sometimes a dollar is just a dollar.

You also linked to the wrong documentation; the formatting syntax documented there only applies to the format() function and the str.format() method. You want to look at the printf-style String Formatting section instead.

Leave a Comment