Python Hello World Program: Learn to Write & Run Your First Code
Python Hello World program example using print function
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.
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!
Before running Python code, you need to install Python on your computer. Follow these steps:
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.
There are two ways to run Python code:
python
and hit Enter.print("Hello World!")
and press Enter.print("Hello World!")
hello.py
.cd
, and run:
python hello.py
Hello World!
printed on the screen.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.
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!