Hello world!

Now that we’re done installing Python, we can move on to writing our first hello world program. To get this done, you only need a text editor. Notepad can work just fine for starters, but moving on you might need one that will respond to your code and allow you spot errors easier.

Creating The Hello World Python Program

Create a new file in your text editor and type the following code

print("Hello World!")
print('Hello World with single apostrophes')
print("Computer says 'Hello'")
print('Human reads "Hello"')

Save your file as Hello.py (files ending with .py are associated with python).

Running The Hello World Python Program

Then open your command prompt and move to the folder where you have saved your file. You can do this by entering the change directory command followed by the path to the folder you need to get in. I’ve saved mine in a py3eg folder in the root of my c:\ so this is what I type in my command prompt.

cd c:\py3eg
python Hello.py

If you do it right and don’t run into any errors, you should see something like this

Hello World!

Based on the output we can tell that Python accepts both the apostrophe (‘) and the quotation mark (“) signs in its print command. If you intend to have any instances of one within what you want to print, then you will need to start and end your string with the other like we did in the example above. We also see that Python begins each print command on a new line

At this point, if you are having any difficulties getting things to work you can leave a comment and I’ll help out. I’ve generally avoided potential errors as they may not be so common and they’d require a lot of time to cover. I am also using a Windows machine to run my hello world and while things might be different on other operating systems, the differences shouldn’t be much of a problem.

Next, we will look at some data types we can work with in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *