Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

printf using old %-syntax

  • printf

  • %

  • This slide is here only as a historical page so when you see the older ways of writing you'll know what you see.

  • It is recommended to use f-strings or if those cannot be used for some reason then use the format method.

v = 65
print("<%s>" % v)     # <65>
print("<%10s>" % v)   # <      65>
print("<%-10s>" % v)  # <65      >
print("<%c>" % v)     # <A>
print("<%d>" % v)     # <65>
print("<%0.5d>" % v)  # <00065>