Python - String String format

Introduction

You can create string text values with string formatting expressions.

Both of the following substitute objects into a string.

Demo

print( 'That is %d %s code!' % (1, 'dead') )           # Format expression: all Pythons 
print( 'That is {0} {1} code!'.format(1, 'dead') )     # Format method in 2.6, 2.7, 3.X

Result

Related Topics