5. Formatting Text Precisely

When programming for business and professional use, you want to format text to create beautiful-looking tables and presentations. In this area, Python has an embarrassment of riches. It has several ways to modify and enhance the printing of information in text-character form.

This chapter presents all three approaches in detail, beginning with the string-formatting operator, %s, which typically provides the quickest, easiest solution. For the most complete control, you may want to use the format function or format method, which support many options, even letting you print large numbers with the thousands-place separator (,).

5.1 Formatting with the Percent Sign Operator (%)

Here’s a simple problem in formatting ...

Get Supercharged Python: Take Your Code to the Next Level, First 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.