8. Input and Output

To be useful, a program needs to communicate with the world around it. It needs to interact with the user, or read and write files, or access webpages, and so on. In general, we refer to this as input and output, or I/O for short.

We’ve already seen basic console I/O, which involves printing messages and using the input function to read strings from the user. Now we’ll see some string formatting that lets you make fancy output strings for console I/O and anywhere you need a formatted string.

Then we’ll turn to file I/O, which is all about reading and writing ...

Get Python: Visual QuickStart Guide, 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.