Chapter 21. Print Formatting and Strings

Waaaayyyy back in chapter 1, you learned about the print statement. It was the first command you ever used in Python. You’ve also seen (in chapter 5) that you can put end='' at the end of a print statement to make Python keep printing the next thing on the same line. You used that to make prompts for input(), until you learned the shortcut of putting the prompt right in the input() function.

In this chapter, we’re going to look at print formatting—ways to make your program’s output look the way you want it to. We’ll look at things like

  • Starting new lines (and when you should do that)
  • Spacing things out horizontally (and lining things up in columns)
  • Printing variables in the middle of a string
  • Formatting ...

Get Hello World! Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.