Name

String Formatting

Examples
age = 7
animal = 'turtle'
weight = 317.5

# Format string to include animal, age, and weight to one digit after the decimal point.
s = ("This %s is %i years old, and weighs %.1f pounds." % (animal, age, weight))
print(s)
Description Substitute variables in a string using the string format operator % as shown above. Symbols that can be used with % include: %i for integers, %f for floats and %s for strings.
Syntax
	"%s" % "string"
	"%i" % 10 
	"%f" % 10.5
Parameters
%sString: any string
%iint: any int
%ffloat: any float
Related string
.find()
.strip()
.join()
.replace()

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.