What Is Python?

Computers do cool and amazing things. However, they rarely do this by themselves. Obviously, they must be instructed before they can do something cool and amazing. Most of the time, we send instructions to computers by pointing and clicking a mouse. boy Other times, the instruction is programmed directly into the computer via a programming language. One of the simplest programming languages today is Python. Python has increasingly become popular because it is easy to learn, especially when compared with other programming languages such as Java or C++. It is also a multi-purpose language - meaning that it is adaptable, flexible, and can be used in several areas such as work, school, or at home. In this tutorial, I will show you some basics of the python programming language. The lessons here use the Windows operating system but all code examples should work in other operating systems as well, including Linux and Mac OS. python. By the end of these lessons, you should be familiar with:


  • installing the python program on a Windows-based computer
  • starting python from the GUI Editor, IDLE
  • creating and saving a python code
  • running a python code
  • knowing how and where to find additional help on python topics
Installing Python

Although Windows operating systems do not come with Python preinstalled, the developers of Python have made it relatively easy to install the Python software on Windows. To do so, follow these steps:

  1. Open your favorite internet browser and go to the following address: https://www.python.org/downloads/. You should see a website similar to the one below:

  2. pyth-downl

  3. Click the Download Python x.xx button (Similar to the highlighted button shown in the above image). This will start a file download. Wait till it finishes
  4. Next, double click the downloaded file to start the installation. When the installation window comes up, click Run
  5. On the next window, check the Add Python x.xx to PATH radio button at bottom of the installation window, then click the INSTALL NOW option at the top. See the image below:
  6. pyth-downl

  7. Another window will come up with a green progress bar showing the installation progress. When the progress bar becomes full, the window will display a Setup was successful message indicating that the installation has successfully completed

Congratulations! You just installed Python on a Windows operating system. Hooray!!

Hello, World!

When you install python, you get a free interactive editor known as IDLE (Integrated DeveLopment Environment). IDLE lets you see real-time results of the code you write. It displays the Python version you are using and three arrow prompts that lets you know when to input commands or instructions. Now lets try and create our first Python code.

  1. Move your cursor to the bottom left corner of your screen and bring up the start option. In the search box, type IDLE
  2. From the result(s) of the search, select IDLE (Python x.xx 32/64 bit). Wait for the IDLE editor to show up on your computer screen. See the next 2 images below for reference:
  3. pyth-downl

    Opening IDLE in Windows

    hello-world

    The IDLE editor (User Interface)

    As mentioned earlier, IDLE is the Python default editor, meaning it ships with Python, and gets automatically installed when you install Python. As can be seen in the image above, IDLE comes with a very simple interface and a few basic features such as auto-indentation, code completion, and syntax highlighting. To use IDLE to write Python codes, we either input commands using the menu bar (highlighted feature in the above image with the tag [1]). The menu bar features several commands, including letting you create and save new files, run a code, view recently edited files, close the editor, and many similar actions. We may also type commands directly into the IDLE shell. We do this by following the interactive prompt (3 right-facing arrows highlighted above with the tag [2]). When the prompt is displayed, it means that the editor is ready to receive a new command or code to be ran. Let's see how this works by running a command:

  4. Bring up the interactive editor, IDLE, following the above steps. In the shell, type:
        
          print('Hello, world!')
        
        
  5. Next, press Enter. You should see a result similar to that displayed in the screenshot below
  6. hello-world

    First Python code in IDLE
Creating Python Files

As mentioned previously, IDLE let you save the code you ran. Since we've written our first code, let's save it so that we know how this is done. In order to save a file in IDLE, we must first create a new one. Let us do that

  1. In IDLE, move your cursor to the File tab on the menu bar, and click it
  2. From the displayed options, select New File. A new IDLE editing window will open.
  3. In the new editing window, type the previous command again: (See image below for reference)
        
          print('Hello, world!')
        
        
  4. hello-world

    Creating a new file in IDLE
Saving the File
  • To save the file, move your cursor once again to the File tab on the menu bar and click it
  • Next, select Save or Save As from the displayed options. A dialog window will open. Choose an appropriate directory to save the file
  • Give your file an appropriate name, make sure the name does not start with a punctuation or a number or it does not contain spaces.
  • After naming the file, click Save to save it to your chosen location. See the image below for reference
  • hello-world

    The IDLE editor (User Interface)
    Running the File

    After saving the file, it becomes a Python file and can be ran in IDLE whenever we want. To rerun the file, follow these steps:

    1. On the IDLE screen, move your cursor to the File option on the menu bar and select Open from the displayed list.
    2. Browse to the location/directory where you saved the file, find the file, click on it once to highlight it then click Save on the dialog box
    3. Next, locate the F5 key on your keyboard, and hit it once.
    4. Similarly, you can move your cursor to the Run option on the newly opened editor's menu bar, then select Run Module from the list of options to run the code. See image below for reference
    5. hello-world

      Running your code

      Well, done. You've successfully created, saved and ran a python file containing a basic python code. You are a python programmer now!

    Summary

    In this lesson, we learned how to install python. We then created our first Python code using IDLE. Again, we've gone over how to save and run a python file containing python codes. In the next modules, we will learn how to do more useful things with the python editor, IDLE



    Check out the following free python resources: