Series: Learning Python: A Comprehensive Beginner Level Tutorial Series 🚀

Hello World Program in Python

Begin Python journey with the classic 'Hello World' program. Our guide covers Python syntax, printing, and examples for a successful start in Python programming
E
Edtoks2:27 min read

The "Hello, World!" program is a simple and traditional first program when learning a new programming language. Here's how you can create and run a "Hello, World!" program in Python:

Writing the "Hello, World!" Program

  1. Open a Text Editor: Open your preferred text editor. This can be a simple text editor like Notepad on Windows, TextEdit on macOS, or any code editor like VSCode, Atom, or Sublime Text.

  2. Write the Code: In your text editor, type the following Python code:

    print("Hello, World!")

    This one-liner prints the string "Hello, World!" to the console.

  3. Save the File: Save the file with a .py extension, for example, hello.py. The .py extension indicates that it's a Python file.

Running the Program

On the Command Line:

  1. Open a Terminal (Command Prompt on Windows): Open a terminal or command prompt.

  2. Navigate to the Directory: Use the cd command to navigate to the directory where your hello.py file is located.

    cd path/to/your/directory
  3. Run the Program: Type the following command and press Enter to run your Python script:

    python hello.py

    If you are using Python 3, use python3 instead of python:

    python3 hello.py

In an Integrated Development Environment (IDE):

  1. Open an IDE: If you are using an IDE like VSCode, PyCharm, or IDLE, open the IDE.

  2. Open the File: Open your hello.py file in the IDE.

  3. Run the Program: Look for a "Run" or "Execute" button in the IDE, or use a keyboard shortcut (often F5). Clicking this will execute your script.

Understanding the Code

  • print("Hello, World!"): This line prints the string "Hello, World!" to the console. The print() function is used to display output.

Conclusion

The "Hello, World!" program is a simple introduction to the syntax and structure of a programming language. Running this program ensures that your Python environment is set up correctly, and you're ready to start coding in Python. As you progress, you'll explore more advanced features and functionalities of the language.