In this chapter you learned how to install Python, and how to work with the Python GUI (IDLE), which is a program written in Python for the express purpose of editing Python programs. In addition to editing files, this “ shell ” allows you to experiment with simple programming statements in the Python language. Among the things you learned to do within the shell are the basics of handling strings, including string concatenation, as well as how to format strings with format specifiers, and even storing strings within that same %s format specifier. In addition, you learned to work with multiple styles of quotes, including the single, double, and triple, and found out what the \n newline escape character was for. Finally, you learned your very first function, print() , and wrote your first program, the Hello World standby, which is a time - honored tradition among programmers; it’s similar to learning “ Smoke on the Water ” if you play guitar — it’s the first thing you’ll ever learn.
1. In the Python shell, type the string, “ Rock a by baby,\n\ton the tree top,\t\when the wind blows\n\t\t\t the cradle will drop. ” Feel free to experiment with the number of \n and \t escape sequences to see how this affects what gets displayed on your screen. You can even try changing their placement. What do you think you are likely to see? 2. In the Python shell, use the same string indicated in Exercise 1, but this time, display it using the print() function. Once more, try differing the number of \n and \t escape sequences. How do you think it will differ?
blog comments powered by Disqus |