Hello World!

Published

2023-07-31

Hello, Python!

It is customary—a nearly universal ritual, in fact—when learning a new programming language, to write a program that prints “Hello World!” to the console. This tradition goes back as at least as far as 1974, when Brian Kernighan included such a program in his tutorial for the C programming language at Bell Labs, perhaps earlier.

So, in keeping with this fine tradition, our first program will do the same—print “Hello World!” to the console.

Python provides us with simple means to print to the console: a function named print(). If we wish to print something to the console, we write print() and place what we wish to print within the parentheses.

print("Hello World!")

That’s it!

If we want to run a program in script mode we must write it and save it. Let’s do that.

In your editor or IDE open a new file, and enter this one line of code (above). Save the file as hello_world.py.

Now you can run your program. If you’re using an IDE, you can run the file within your IDE. You can also run the file from the command line, for example,

$ python hello_world.py

where $ is the command line prompt (this will vary from system to system). The $ isn’t something you type, it’s just meant to indicate a command prompt (like >>> in the Python shell). When you run this program it should print:

Hello World!

Next steps

The basic steps above will be similar for each new program you write. Of course, as we progress, programs will become more challenging, and it’s likely you may need to test a program by running it multiple times as you make changes before you get it right. That’s to be expected. But now you’ve learned the basic steps to create a new file, write some Python code, and run your program.

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

This material is for free use under either the GNU Free Documentation License or the Creative Commons Attribution-ShareAlike 3.0 United States License (take your pick).