Skip to content

String Formatting

Dirk van Oosterbosch edited this page Nov 6, 2015 · 1 revision

String Formatting is an operation in a computer program to format a text string, based on one or more dynamic variables. This can be compared with using a Template with placeholders: the value of the placeholders are filled into the template when the string is formatted.

In python these are the most used types of placeholders:

  • %s for String
  • %d for Integer digit
  • %f for Float

Example:

"To buy %d %s will cost you %f" % (3, "beers", 7.5)

outputs:

'To buy 3 beers will cost you 7.500000'

See (pyformat.info)[https://pyformat.info] for more documentation

Clone this wiki locally