How to write Hello, World in Python: tips and tricks

Today, Python is considered one of the most popular programming languages ​​in the world, a large number of its fans appear annually. Those who want to learn this language most often begin by writing the simplest first program - displaying the phrase Hello, World. This is considered a good tradition by programmers around the world. Let's take a look at how to write Hello, World! in Python.

python code

Python installation

Before you write your first program, you need to make sure that the necessary software is installed and configured on your computer in order to get started.

You will need to install Python on your computer. This article will describe the installation method for the Windows operating system.

You will need to go to the official site dedicated to the Python language (you can see it by typing the appropriate request in any search engine) and download the installer from the main page.

After the download is completed, you need to run the installer and follow the simple instructions on the screen. There is no need to change or delete any of the items proposed, if you are just starting to learn the language, the program will prompt the best option.

After a couple of minutes, the installation will be completed, and on your computer everything you need will appear to write in Python Hello, World.

Writing a program

Now you need to run a special development environment, which is already preinstalled on your computer, if the previous step is completed correctly.

Go to the "Control Panel" and type in the search IDLE. You will immediately see a selectable IDLE item (Python GUI). Run this program.

In the window that opens, select the "File" item from the top menu, open a new window (New Window).

In front of you on the screen you will see an editor in which you will need to write the following code:

print "Hello, World!" 

The resulting will need to be saved in a separate file. Let's call it, for example, hello.py.

Now it will be possible to look at what happened. To do this, select Run in the top menu of the development environment where the code is written, then select Run Module in the drop-down list. The second way to start the finished program is even easier, just press the F5 key.

After the indicated actions are completed, a window will open in which the corresponding inscription will be displayed. So, the program is written correctly and processed successfully.

python infographics

Error handling

If there is any inaccuracy in the code, the program cannot be launched, in which case an error will be displayed on the screen. For example, one incorrectly written letter will produce a window with the words Syntax error.

At the same time, it will be very simple to correct the committed inaccuracy, Python will show in which section the code was written incorrectly.

So now we’ve figured out how to write in Python Hello, World on Windows. This can be considered a successful first step towards starting programming.

Source: https://habr.com/ru/post/K4273/


All Articles