Programming with Python

Downloading Python and writing a Hello world program

To start coding in python you have to have it installed on your computer. If you are using mac or linux type "python" into your terminal. If it is installed it will list the version. If you get an error then you need to download and install it.

If you are using windows: Press windows key; type "cmd" to bring up the command line; type "python". If you see:

 Microsoft Windows [Version 10.0.18362.356]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\MALONE>python
'python' is not recognized as an internal or external command,
operable program or batch file.

then you need to install it. Install it at https://www.python.org/downloads.

The first program to write is a "Hello world" program. Open the program "IDLE" that you installed. this is the IDE for python. An IDE is an Integrated Development Enviroment. This is like a text editor where you write code and then save it as a program that you can open later to run or edit and add to.

Open your IDE either IDLE or python shell. It should say something like this at the top:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
	   Type "help", "copyright", "credits" or "license()" for more information.
       >>> 
       

A blinking cursor will be after the three ">" right acute angle brackets. This is where typed text will appear. Type:

>>> print("Hello World")
             

Then press enter. Your screen should look like:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
	   Type "help", "copyright", "credits" or "license()" for more information.
       >>> print("Hello World")
       Hello World
       >>>
       

After pressing enter, it printed "hello World" in the next line below. Three angle brackets like ">>>" indicates a new line in python.

We have written our first program. To save it open the file menu and select "save as". A dialog box opens in file explorer to chose where to save and under what filename. Save it in documents or a special folder you create and then choose the filename "HelloWorld.py". Python files end in ".py" It doesn't really matter what file name you choose as long as you end with the .py file extension. I am going to be boring and save it as helloworld.py because it is simple and easy to identify. Using weird names makes organzation suffer. You will lose your files and be disorganized.