How to create Hello World program in Python using IDLE

Total Views : 117
Zoom In Zoom Out Read Later Print

IDLE is a simple editor for Python, that comes bundled with Python. Let's create and run a simple Hello World program in python using IDLE.

How to create Hello, World program in IDLE

Open IDLE on your system of choice.

In older versions of Windows, it can be found at All Programs under the Windows menu.

In Windows 8+, search for IDLE or find it in the apps that are present in your system.

On Unix-based (including Mac) systems you can open it from the shell by typing $ idle python_file.py.

It will open a shell with options along the top.

In the shell, there is a prompt of three right angle brackets:

>>>

Now write the following code in the prompt:

>>> print("Hello, World")

Hit Enter.

>>> print("Hello, World")
Hello, World
Hello World Python file

Create a new file hello.py that contains the following line:

Python 3.x Version ≥ 3.0

print('Hello, World')

Python 2.x Version ≥ 2.6

You can use the Python 3 print function in Python 2 with the following import statement:

from __future__ import print_function

Python 2 has a number of functionalities that can be optionally imported from Python 3 using the __future__

module, as discussed here.

Python 2.x Version ≤ 2.7

If using Python 2, you may also type the line below. Note that this is not valid in Python 3 and thus not

recommended because it reduces cross-version code compatibility.

print 'Hello, World'

In your terminal, navigate to the directory containing the file hello.py.

Type python hello.py then hit the Enter key.

$ python hello.py
Hello, World

You should see Hello, World printed to the console.

You can also substitute hello.py with the path to your file. For example, if you have the file in your home directory

and your user is "user" on Linux, you can type python /home/user/hello.py.

See More

Latest Photos