πŸš€ Join our community of 100,000+ learners worldwide! β€’ πŸ“š 2000+ free tutorials available β€’ πŸŽ“ Get certified today! β€’ πŸ’‘ Learn at your own pace β€’ 🌟 New courses added weekly β€’ 🀝 Connect with expert instructors
Python - Hello World Program - Ngahtech Tutorials

Python - Hello World Program

0 min read Python - Hello World Program / Python - Hello World Program
Free Text

Python - Hello World Program

This tutorial explains how to write a simple Hello World program using the Python programming language. The program uses Python’s built-in print() function to display text on the screen.

Hello World Program in Python

Printing "Hello World" is usually the first program written in any programming language. In Python, this program does not require any user input. It simply displays a message on the screen and is used to confirm that Python is correctly installed and working.

Steps to Write a Python Hello World Program

Step 1: Install Python

Ensure that Python is installed on your system. If not, download and install it from:

https://www.python.org/downloads/

Step 2: Choose a Text Editor or IDE

Select a code editor or IDE such as:

  • VS Code
  • PyCharm
  • Thonny
  • Notepad++

Step 3: Create a New File

Open your editor and create a new file.

Step 4: Write the Code

Write the Python code to print "Hello World".

Step 5: Save the File

Save the file with a .py extension, for example:

hello.py

Step 6: Run the Program

Execute the program using a terminal or command prompt.

Python Program to Print Hello World

# Python code to print "Hello World"
print("Hello World")

In the above code:

  • The first line is a comment, which is ignored by Python.
  • The second line uses the print() function to display the message on the screen.

Output

Hello World

Different Ways to Run a Hello World Program

1. Using Python Interpreter (Command Prompt Mode)

You can run Python directly from the terminal.

Windows Example:

PS C:\> python
>>> print("Hello World")
Hello World

Linux Example:

$ python3
>>> print("Hello World")
Hello World

This method allows you to execute Python code line by line in interactive mode.

2. Using Script Mode

You can also write Python code in a file and run it as a script.

Step 1: Create a file named hello.py

print("Hello World")

Step 2: Run the file

Windows:

C:\> python hello.py

Linux:

$ python3 hello.py

Output:

Hello World

3. Using Shebang (

#!

) in Linux

In Linux systems, you can make a Python file executable.

Step 1: Add shebang line

#!/usr/bin/python3

print("Hello World")

Step 2: Give execute permission

$ chmod +x hello.py

Step 3: Run the script

$ ./hello.py

Output:

Hello World

FAQs

1. Why is the first program called Hello World?

It is a simple program used to test whether the programming environment is correctly set up.

2. Is Python installation required to run Hello World?

Yes, Python must be installed on your system unless you use an online compiler.

3. Can I run Python without installing it?

Yes, you can use online Python compilers to run your code directly in the browser.

4. Is there any difference between first program and Hello World program?

No. The first program in Python is commonly called the Hello World program.

5. What are the ways to print "Hello World" in Python?

You can use:

  • print() function
  • sys.stdout.write() (using the sys module)
  • f-strings in Python formatting

Conclusion

The Hello World program is the simplest way to start learning Python. It helps beginners understand how to write, save, and execute Python code while confirming that the programming environment is properly set up.