Page 95 - Beginning Programming with Pyth - John Paul Mueller
P. 95

white space (such as extra lines between lines of code). Python ignores any indentation in your application. The main reason to add indentation is to provide visual cues about your code. In the same way that indentation is used for book outlines, indentation in code shows the relationships between various code elements.
The various uses of indentation will become more familiar as you work your way through the examples in the book. However, you should know at the outset why indentation is used and how it gets put in place. So it’s time for another example. The following steps help you create a new example that uses indentation to make the relationship between application elements a lot more apparent and easier to figure out later.
1. Choose New ⇒ Python3.
Jupyter Notebook creates a new notebook for you. The downloadable source uses the filename BPPD_04_Indentation.ipynb, but you can use any name desired.
2. Type print(“This is a really long line of text that will” +.
You see the text displayed normally onscreen, just as you expect. The plus sign (+) tells Python that there is additional text to display. Adding text from multiple lines together into a single long piece of text is called concatenation. You learn more about using this feature later in the book, so you don’t need to worry about it now.
3. Press Enter.
The insertion point doesn’t go back to the beginning of the line, as you might expect. Instead, it ends up directly under the first double quote, as shown in Figure 4-19. This feature is called automatic indention and it’s one of the features that differentiates a regular text editor from one designed to write code.
4. Type “appear on multiple lines in the source code file.”) and press Enter.
Notice that the insertion point goes back to the beginning of the line. When Notebook senses that you have reached the end of the code, it automatically outdents the text to its original position.
5. Click Run.
You see the output shown in Figure 4-20. Even though the text
  






















































































   93   94   95   96   97