So here comes the exciting part. We begin with a tiny bit of Python programming. To create your first Python program we will do it the classic way. We will create Python “Hello World” Program. It will be done both ways on the command prompt of Python shell with IDLE and by creating and saving a Python file in IDLE editor.
Python Hello World Program on the Command Prompt of IDLE
Open IDLE from the Python group in your programs as described in the Installation of Python. On the prompt identified by “>>>” type the following statement. Press enter after you complete.
>>>print(‘Hello World !’)
After you press enter the string passed to print() function are displayed right below it. This completes the execution of your first Python Statement.
This is a simple and powerful interface to try the python commands individually. You can run multiple Python commands in one session but you cannot save them. For that you have to create a Python script discussed in the following section. Since you are working in Windows you can close the Python shell with IDLE by clicking the close button or typing exit() on >>> prompt.
Python “Hello World” Program Writing and Saving with IDLE Editor
Now launch IDLE Editor by selecting File-> New File from Python shell with IDLE. You would be able to have an editor just like Windows Notepad. The difference is that this editor recognizes the Python commands and colors then for your convenience. When you save your file, this editor prompts for file name with .py extension.
Before you begin your Python scripts it will be preferable for you to create a folder (In all examples we will be saving our files in my_python_work folder) where you will save the programs.
Open editor and type
print(“Hello Python world!”)
Now from the File menu of the editor select Save option. Write name of the file in file name textbox. You can see the ‘Save as Type’ box already contains ‘Python Files’. Now Click ‘Save’ Button and you have successfully created your first Python script file.
To run this file within the IDLE Editor, select Run->Run Module or press F5.
The output will be reflected in the shell
Opening and Editing Existing Python files with IDLE Editor
You can always open an existing Python file and edit it. Go to the folder that contains your saved Python programs. Right click on a file and select Open with IDLE -> Edit with IDLE. You will see that your file has opened with IDLE editor. Now you can update it by adding more statements and save it to run it again using F5 or Run-> Run Module.
Be First to Comment