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.


examples/format/printf.py

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>