The Python “Hello World” program is usually the first program a coder will write in Python. This program uses a print statement to display a string to the Python console. The program looks like: print(“Hello World”).
One of the very first programs you can write to make sure your Python version works is “Hello World”. There are two ways to create the program: in a terminal or in your code editor of choice (i.e. Visual Studio Code, Vim, etc.).
Make sure you have Python 3 installed on your machine to get started.
In this guide, we’re going to talk about how to write a “Hello World” program in the Python programming language.
Python Hello World: Using the Terminal
In your terminal, type “python3” to open the Python Interpreter. In most cases, this works, but some operating systems may use “python” or “py” as the command to open the Python Interpreter. As long as it starts a Python version greater than 3, you’re fine!
To learn more about interpreters, read our guide on Python interpreters.
Hello World in Python: Your Instructions
Input print(“Hello World”) into the Interpreter.
This is a line of code. Each line of code is an instruction to the computer that it will follow when you run your program.
81% of participants stated they felt more confident about their tech job prospects after attending a bootcamp. Get matched to a bootcamp today.
The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.
Let’s break down this line of code:
- print() tells Python that you want to print a value.
- “Hello World” is a Python string. A string is a series of characters. This string appears between the parentheses in our print() statement. We do this so that the print() statement knows we want to print the string.
Our “Hello World” string must appear in quotation marks. You can use single or double quotation marks. Quotation marks are necessary because they tell Python that you are working with a string.
If we did not enclose our string in quotation marks, Python would not know the difference between our string and our code.
“Hello World” should show up on the next line! Let’s run our code and see what happens:
Our code executes successfully. We can tell because “Hello World” appears on the line immediately after our code. You have just written your first Python program!
The >>> indicates a line on which you have written code. Every time a program finishes running in the terminal, the >>> will appear. When these arrows appear, you know that the terminal is ready to accept another line of code.
These lines do not appear on the “Hello World” line. This is because this line has been created by the program itself rather than us, the coder.
- Career Karma matches you with top tech bootcamps
- Get exclusive scholarships and prep courses
Hello World Python: Code Editor (i.e. Visual Studio Code)
Open up your editor of choice and create a new file and save it as hello.py. In your file, input print(“Hello World”) into the file and save it.
This is the same code that we used earlier.
In your terminal, navigate to the directory/folder you saved your file. Use cd and ls to navigate from directory to directory. Use python3 hello.py to run the file. Hello World should show up on the next line.
The “play” button in the upper right hand corner of VS Code runs the current file. We can see the output of our code on the lower half of the screen. VS Code is the environment in which our code is written. But you may use a tool like Atom or Sublime Text or another programming environment.
That’s it! You have successfully created a simple program in Python that shows that your environment works.
You can now say that you have written a program in the Python programming language. Congratulations!
This program may seem simple, and it is. But without working on simple programs you’ll never get anywhere learning to code. Programs like “Hello World” teach the basics of coding so that you can build the knowledge you need to create more advanced programs.
You may be wondering what’s next. Consider taking a look at Python variables. These are labels you can use to store values, like strings and numbers, in your code.
For a challenge, try to print “Hello Kevin” to the console. All you need to do is change the text in the string. This will show you that Python will print out whatever appears in the string.
For guidance on top Python learning resources, online courses, and books, check out our How to Learn Python guide.
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.
"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"
Venus, Software Engineer at Rockbot