VMware ESXi and vSphere Cluster Management

Hello World: Your First Program

Learn how to create, save, run, and troubleshoot a simple Python Hello World program as your first programming exercise.

What Is a Hello World Program?

Hello World is a traditional first program that displays a short greeting, such as Hello, World!. It is intentionally small so you can focus on the basic programming workflow.

A program is a set of instructions that a computer can execute. The instructions you write are called source code: human-readable code written in a programming language.

A working Hello World exercise confirms that several parts of your setup work together:

  • You can create and save a source file.
  • Your code editor or IDE can open the file.
  • The Python interpreter is installed and available.
  • The program can run and produce output.

In this lesson, Python is used because its message-output instruction is short and beginner-friendly. An interpreter executes Python source code directly, so Python programs do not require a separate compile step for this example.

Prepare a Project Folder and Source File

You need a plain-text code editor, such as a basic programming editor, or an IDE. An IDE, or integrated development environment, combines code editing with tools for running and sometimes debugging programs.

  1. Create a recognizable folder such as hello-world in your documents or programming workspace.
  2. Open your editor or IDE.
  3. Create a new plain-text source file.
  4. Save it inside the project folder with the exact name hello.py.

The .py extension identifies the file as Python source code. Make sure your editor does not silently add another extension, such as .txt. A file named hello.py.txt is not the same as hello.py.

Write the Message-Output Instruction

Enter this line in hello.py:

print("Hello, World!")

print is Python's built-in function for displaying information. The text between the parentheses is a string, which means a sequence of text characters.

The quotation marks tell Python where the string begins and ends. They are not part of the displayed message. These two forms are both valid:

print("Hello, World!")
print('Hello, World!')

Use matching quotation marks: an opening double quote must be closed by a double quote, and an opening single quote must be closed by a single quote. Python is case-sensitive, so print is valid but Print is not. Python does not require a semicolon at the end of this statement, and indentation is not needed for this one-line program.

Run the Program

Save the file before running it. From a terminal, change to the project folder and run the source file with Python:

python hello.py

On systems where the Python command is named python3, use:

python3 hello.py

If you use an IDE, open hello.py and choose its Run control. The exact label may be Run, Run Python File, or a similar option. The output normally appears in a terminal, console, or output panel.

Python uses an interpreter. The interpreter reads and executes the source code when you run the command. In a compiled language, the workflow has two distinct stages: a compiler first translates source code into an executable form, and then you run that executable. The runtime is the environment or process in which the program executes.

Check the Expected Output

The output should be exactly:

Hello, World!

Compare the output with both your source code and your intended greeting. Capitalization, spaces, commas, exclamation marks, and other punctuation are part of the result. For example, Hello, world! is different from Hello, World!.

Small differences in syntax, the required rules for writing valid code, can prevent a program from running. A missing quotation mark or a misspelled function name changes the meaning of the code or makes it invalid.

Personalize the Message

Replace the greeting with another message:

print("Welcome to programming, Sam!")

Save the file, run it again, and check that the new output appears:

Welcome to programming, Sam!

This is the basic programming iteration cycle:

  1. Edit the source code.
  2. Save the file.
  3. Run the program.
  4. Observe the output.
  5. Compare the result with what you expected.

Try changing only the text inside the quotation marks. The print instruction stays the same while the string changes.

Recognize and Fix Common Errors

Errors are normal feedback while programming. Read the first useful part of an error message: it often identifies the error type, the file, and the line where Python noticed a problem. The actual cause may be slightly earlier on that line, so inspect the complete statement.

ProblemLikely causeHow to fix it
Invalid syntaxMissing or mismatched quotation marks, a misspelled output function, or missing punctuationCompare the line with print("Hello, World!") and correct the first reported error.
Nothing appearsThe wrong file was run, the file was not saved, or the output panel is hiddenSave the file, confirm the selected run target, and look in the terminal, console, or output panel.
The command cannot find the fileThe filename or extension is wrong, or the terminal is in a different folderVerify that the file is named hello.py and run the command from the folder containing it.
The command cannot find PythonPython is not installed or is not available through the system pathConfirm that Python is installed or use the interpreter configured by your IDE.
Old output appearsChanges were not saved, or an older copy is being runSave the current file and verify that the command or IDE uses the intended hello.py.

Hello World Workflow

StepActionExpected result
1Create a project folderYou have a recognizable place for the program.
2Create and save hello.pyThe source file has the correct Python extension.
3Write the print instructionThe file contains a string and a valid output command.
4Run python hello.pyThe Python interpreter executes the file.
5Check the terminal or output panelYour greeting appears exactly as intended.
6Edit, save, and run againThe output reflects the changed greeting.

Key Terms

  • Hello World: A traditional first program that displays a short greeting.
  • Source code: Human-readable instructions written in a programming language.
  • Code editor: A tool for creating and modifying source code.
  • IDE: An integrated development environment that combines editing and program-running tools.
  • Output: Information produced when a program runs.
  • String: A sequence of text characters, usually enclosed in quotation marks.
  • Syntax: The rules a programming language requires for valid code.
  • Interpreter: A program that executes source code directly.
  • Compiler: A program that translates source code into executable form before it runs.
  • Runtime: The environment or process in which a program executes.

What to Learn Next

Once this program works, useful next topics include running programs from the command line, variables and data types, input and output, comments, debugging, and basic project structure.