Chapter 21. Print Formatting and Strings

Waaaayyyy back in chapter 1, you learned about the print statement. It was the first command we ever used in Python. We’ve also seen (in chapter 5) that you can put a comma at the end of a print statement to make Python keep printing the next thing on the same line. We used that to make prompts for raw_input(), until we learned the shortcut of putting the prompt right in the raw_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. ...

Get Hello World! Computer Programming for Kids and Other Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.