To learn how to program in Python
- All: To run your first program
- Most: To edit a Python program, and learn some Python keywords
- Some: To learn about different versions of Python
What is Python?
Python is a computer programming language, that lets you create a set of commands (also called code) that solves a problem.
The Python programming window
These lesson use a Python programming window (shown below, from Trinket), that lets you run, and optionally edit Python programs.
For example, the following Python code on the left, on the line beginning with the number 1, prints the string “Hello World” to the adjacent window on the right.
Python programming window
- Click the ▶ run button to execute the program on the left, and see the results in the window on the right. Well done, you have successfully run your first Python program.
- Edit the phrase “Hello World”, and re-run the program. Well done, you have successfully edited and run your first Python program. Do not remove the quotes, or the brackets, otherwise Python will generate an error message.
- code: one or more instructions understood by a computer program
- command: an instruction understood by a computer program
- computer program: a set of instructions (also called commands or code) that solves a problem
- execute: to process a computer program, also called: run
- Python: a computer language
- run: to process a computer program, also called: execute
- string: computer terminology for one or more characters (letters, punctuation, and digits). A specific string is called a literal string, eg. the postcode: “CW4 7AT” is a literal string that consists of letters and digits.
Python is available in two versions:
- Python v2 – The older version of Python, for which there are no major enhancements planned. It is available for historical reasons, such as running programs written in the old version.
- Python v3 – The newer version of Python, which has significant enhancements over the older v2. This is the recommended version, and the version used in this tutorial.
Running Python on your PC (with IDLE)
You can download, install and run Python on your own PC, from the official “Download Python” page. This will also install IDLE, the “Integrated DeveLopment Environment”, where you write, save and run your own programs. For information on how to install Python/IDLE, see “How to Install Python“.
When you run Python/IDLE on your PC, a “Shell” window will appear. You can enter Python commands in the Shell, and instantly see the results. But if are going to write more than a few lines of code, go to the Shell’s File menu, and click New File. This will open a program window, which requires that you save your program before it runs.
- Official Python website – documentation and download (including IDLE)
- Python 3 @ Trinkets – Write, test and edit code online
- Learn Python @ CodeAcademy – Mainly free, but some premium lessons
- Python 3 tutorial + Snakify – 100+ free exercises
- learnPython.org – Free online interactive Python Tutorials
- Learn Python Programming – Python Tutorials at programiz.com
- Python Course – Python courses at python-course.eu
- Coding Games and Programming Challenges at codingame.com
- Object-Oriented Programming in Python, University of Cape Town
- Problem Solving with Algorithms and Data Structures using Python, Runestone Academy