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 O’Reilly online learning.

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