Python Hello World Program: Learn to Write & Run Your First Code

3/22/2025

Python Hello World program example using print function

Go Back

Python Hello World Program: Learn to Write & Run Your First Code

Introduction

Python is one of the easiest programming languages for beginners. The best way to start is by writing your first Python program: printing “Hello World!” This simple program helps you understand the basics of Python and how it works.

Python Hello World program example using print function

How to Print “Hello World” in Python

To print “Hello World!” in Python, use the print() function as shown below:

print("Hello World!")

When you run this code, Python will display:

Hello World!

Installing Python

Before running Python code, you need to install Python on your computer. Follow these steps:

  1. Download Python from the official website: python.org.
  2. Install Python by following the on-screen instructions.
  3. Verify Installation by opening the terminal or command prompt and typing:
    python --version
    
    If Python is installed correctly, it will display the installed version.

If you don’t want to install Python, you can use an online Python compiler like Google Colab or Replit.

Running Your First Python Program

There are two ways to run Python code:

  1. Using an Interactive Shell:
    • Open your terminal or command prompt.
    • Type python and hit Enter.
    • Type print("Hello World!") and press Enter.
  2. Using a Script File:
    • Open a text editor (Notepad, VS Code, or PyCharm).
    • Type the following code:
      print("Hello World!")
      
    • Save the file as hello.py.
    • Open the terminal, navigate to the file location using cd, and run:
      python hello.py
      
    • You will see Hello World! printed on the screen.

Creating a Function to Print “Hello World”

Functions make Python code reusable and organized. Here’s how to create a function to print a custom message:

def print_message(name):
    print("Hello", name, "!")

print_message("Alice")

Output:

Hello Alice!

This function takes a name as input and prints a personalized greeting.

How to Learn Python Faster

  1. Practice Daily: Write small Python programs to improve your skills.
  2. Use Online Courses: Platforms like Codecademy, Udemy, and Coursera offer Python courses.
  3. Read Python Documentation: Learn from the official Python documentation.
  4. Join Python Communities: Engage in forums like Stack Overflow and Reddit.
  5. Work on Projects: Create small projects like calculators or to-do lists.

Conclusion

Now that you’ve written your first Python program, you are ready to explore more features of Python. Keep practicing and learning to become a Python expert!

Start coding today!

Table of content