Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Chapter 12. Input/Output

There will be lots of times when you want your program to interact with the user (which could be yourself). You would want to take input from the user and then print some results back. We can achieve this using theraw_input andprint statements respectively. For output, we can also use the various methods of thestr (string) class. For example, you can use therjust method to get a string which is right justified to a specified width. Seehelp(str) for more details.

Another common type of input/output is dealing with files. The ability to create, read and write files is essential to many programs and we will explore this aspect in this chapter.