Section 1.7 A Typical First Program
Traditionally, the first program written in a new language is called Hello, World! because all it does is display the words, Hello, World! In Python, the source code looks like this.
This is an example of using the print function, which doesn’t actually print anything on paper. It displays a value on the screen. In this case, the result is the phrase:
Hello, World!
Here is the example in activecode. Give it a try!
The quotation marks in the program mark the beginning and end of the value. They don’t appear in the result.
Some people judge the quality of a programming language by the simplicity of the Hello, World! program. By this standard, Python does about as well as possible.
Check your understanding
Checkpoint 1.7.1.
The print
function:
sends information to the printer to be printed on paper.
- Within the Python programming language, the
print
function has nothing to do with the printer.
displays a value on the screen.
- Yes, the
print
function is used to display the value of the thing being printed.
tells the computer to put the information in print, rather than cursive, format.
- The format of the information is called its font and has nothing to do with the
print
function.
tells the computer to speak the information.
- That would be a different function.
Time to do some experimenting. In the activecode window below, write a program that will display the words My program works!
.
Once you get that working, see if you can do more than one print
in a Python program. Try changing the program so that it will display two lines of output:
My program works!
I wrote it in Python.