Hardware Reference
In-Depth Information
When a program gets to be more than a few lines, it becomes harder to understand
and edit the code. Breaking a program's code down into small sections makes it
easier to read and edit. A function is an example of a small section of code that
does a speciic task, and once it is created you can use it over and over again.
An added beneit of using functions is that if you ix a bug you only have to ix it
in one place.
Like most programming languages, Python includes some standard functions
that the computer will already understand, like the Python 3 print() function
that prints some text to the screen. You can also write your own functions, which
you will do towards the end of this adventure.
A string refers to data or information entered as text (i.e., a “string” of characters).
Place your cursor directly after the >>> prompt and type the following line:
print(“I am an Adventurer”)
Press Enter and see what happens (see Figure 5-3).
FIGURE 5-3 he print() function in action
T
When you press Enter, the Python Shell “interprets” your code. In this case, you
gave the command to print the text between the quotation marks to the screen.
Well done! You have created your irst computer program in Python.
Search WWH ::




Custom Search