Table of Contents
Toggle
This tutorial will teach you how to write a simple Hello World program using the Python programming language. This program will make use of Python’s built-in print() function to print the string.
Printing “Hello World” is the first program in Python. This program will not take any user input but will print text on the output screen. It is often used to test if the Python installation and environment are correctly set up.
.py.
# Python code to print "Hello World"
print("Hello World")
Hello World
You can directly run the print() function in the Python interpreter. Here’s how it looks:
PS C:\> python
Python 3.11.2 (tags/v3.11.2:878ead1) [MSC v.1934 64 bit] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
Hello World
Save the code in a file named hello.py and execute it using the following commands:
C:\> python hello.py
Hello World
$ python3 hello.py
Hello World
#! in Linux ScriptsAdd a shebang line to make the script executable directly:
#!/usr/bin/python3
print("Hello World")
Make the file executable with:
$ chmod +x hello.py $ ./hello.py Hello World
print() methodsys.stdout.write() method (requires sys module)