Okay, okay. If you’ve ever read any other programming tutorial, you know that ‘hello,
world’ has been over done. But this has got to be the most simple program language in
which to do it.
In command prompt mode enter:
print "Hello, world!"
Note: This tutorial is geared for any version of Python before Python 3.0. However
the upgrade should only affect the print function in this tutorial so those of you using
Python 3.0 or higher should use print (” Text here” ) or print (” Text here”, x), where x
is a variable
Exciting stuff. Now lets make that into a program. In your editor type the same thing
(IDLE users go to File, then New, type your program in and hit F5 to run your
program, it will ask you to save. Make sure you add a .py extension at the end).
If you have decided not to use IDLE:
Linux, unix, or dos users – save your program with a .py extension, and then go into
the directory containing the program. type python filename.py
Window users- Save your program with a .py extension and then go into My
Computer or Windows explorer and find your file. Right click on that file and go to
Open With. If python is on that list select that, otherwise go to browse, then to the
directory python is in. Select python.exe.(Note: If you run the above program this
way, it will probably just flash on screen really fast, your other option is to go into
If all went well you have just created your first program! Woohoo.
So whats going on in this program? Very simple. We use the print command to output
our text string to the screen. A string is just what it sounds like. A line of characters
that are grouped together. In this case with quotation marks. Be aware that you can
use ” ” or ‘ ‘ .
Lets try another one. If you want you can write over your first program, or you can
save them all for reference.
print "Hello world! " * 3 print "Goodbye!"
Hello world! Hello world! Hello world! Goodbye!
The first line in this one you see something new, the ‘‘ operation. ‘‘ means to
multiply. Notice I used a couple spaces after Hello world! in the quotation marks. If I
hadn’t, the output would’ve been:
Hello world!Hello world!Hello world!
Not very pretty. Also notice that “Goodbye!” automatically outputs on the next line.
If you want to add new lines from the same print command use \n in the quotation
marks. For example in our previous program change the first line to look like this:
print "Hello world!\n" * 3
Hello world! Hello world! Hello world!