Life
Copyright © 2024 Jiri Kriz, www.nosco.ch

Learning Python

Comments (0)
Introduction to Python for beginners. No programming skills are assumed. The installation covers Windows only.

Introduction

I present here what I think is the simplest start with Python on Windows for non-programmers.

Use English everywhere: for the names of the folders, for the names of your programs, for comments in your programs. English is the language of programming.

Do not use spaces in the names of the folders and in the names of your programs. Everything is easier when there are no spaces in the names, e.g. when you later use Unix tools like "cygwin" on your PC. Consequently do not install Python in the standard Windows directories (i.e. folders) "C:\Program Files" or "C:\Program Files (x86)" because the names contain spaces.

A possible directory structure could be:

I will refer to this structure in the description below.

Installation on Windows

Download the latest Python version from python.org. This is currently the version 3.9.7. Use "Customize Installation" and proceed according to the following snapshopts.

P_i1 P_i2 P_i3

Press "Install" and agree to the Installation. After a short time you get:

P_i4

The window shows the links:

Python Shell

The directory "C:\Programs\Python\Python39" was filled with the installation of Python. Open it in the Windows Explorer and double click on "python.exe". The Python shell will open where you can type Python statements that will be immediately executed:

Shell

We will not be using this window presently so close it.

It is useful for later convenience to create a shortcut for "C:\Programs\Python\Python39\python.exe" say "PY".

IDLE Shell

In the Windows Explorer navigate to "C:\Programs\Python\Python39\Lib\idlelib" and double click on "idle.py". Two windows will appear on the screen:

Idle1

The IDLE Shell can be used as a Python "command interpreter". An interpreter can useful for simple calculations but not for programs because everything will be lost after we close the window. We will write Python programs and save them for future usage. To this purpose click on "File/New File":

Idle2

A new window "untitled" appears.

The First Python Program

Into the "untitled" window type:

# My first Python program
print("Hello World")
Idle3

The first line starting with "#" is a "comment", that is not executed by Python. The second line is a command to print the "string" (a message) inside the quotes. Use the menu command "File/Save As" to save the window content in the file "HelloWorld.py" in "D:\Devl\Python". The name of the program window changes to "HelloWorld.py". Python programs (also called "scripts") should have the extension ".py".

Idle4

Select the menu item "Run/Run Module" (or press F5) to execute the program. The string "HelloWorld" is written onto the Shell window.

Idle5

Congratulations - you developed your first Python program!

When you remain with IDLE, then create a shortcut (say IDLE.py) to "C:\Programs\Python\Python39\Lib\idlelib\idle.py" and put it on your desktop.

Idle6

IDLE is then started by a double click on the icon.

Notepad++ and a Windows Shell

Probably all developers on Windows have the excellent, free editor "Notepad++" and I recommend to download it. Use the "Installer" on the download page and install the latest available version (currently 8.1.4 - 32-bit) in "C:\Programs\Notepad++". You can write your Python programs with this editor and save them in your development folder ("D:\Devl\Python").

For easy access create a shortcut for "C:\Programs\Notepad++\notepad++.exe", name it "Notepad++" and put it on the desktop. Double click this shortcut and in the Notepad++ open your "HelloWorld.py" program.

Notepad_1

Modify your program as you like and save it again. Execute this program using "python.exe" (or using the shortcut "PY" if you have defined it) in a Windows command shell. A simple method is to start the "Windows Power Shell". Right click on the Windows Start Menu on the left bottom of the screen and select "Windows Power Shell". Then navigate to the directory with your Python programm. Execute the program as "PY HelloWorld.py" (or "python.exe HelloWorld.py").

shell_2

If you do not have the "Windows Power Shell" then use the standard "cmd" window. Right click on the Windows Start Menu and select "Run", then enter "cmd" into the Open field and press OK.

cmd

In the command shell navigate to the directory with your Python programm. Execute the program as "python.exe HelloWorld.py".

cmd2

Further Steps

Links

Comments

New Comment