Python introduction: Difference between revisions
Jump to navigation
Jump to search
(Created page with "== Overview == * The Python programming language is one of the most universal computer languages used today. * The makers of the Raspberry Pi though so highly of the language...") |
No edit summary |
||
| Line 9: | Line 9: | ||
* Run python3 code in the Python Shell Window | * Run python3 code in the Python Shell Window | ||
* Run python programs in the Python Editor Window | * Run python programs in the Python Editor Window | ||
== Installing Python3 IDLE == | |||
* To make programming in Python3 easier we will be using an Integrated Development and Learning Environment (IDLE). * There are many different development environments available for Python. | |||
* Other common environments include: Thonny, PyCharm and iPython. | |||
* In this example we will install the Python3 IDLE using the Terminal on the Raspberry Pi. | |||
* When we need to install programs on the Raspberry Pi we always use the Terminal. | |||
* To install software, we use an application manager called apt. | |||
=== Installing Python3 IDLE === | |||
* Open the '''Terminal''' on the Raspberry Pi | |||
* Update our existing software libraries by entering the command '''sudo apt-get update''' | |||
* We always need to update our software libraries before we install new software. | |||
* This because software sometimes needs other software to help make it work. | |||
* The additional software components are called dependencies. | |||
* If we install an older version of the software, some of the dependencies may have changed and this could make our program run erratically. | |||
[[File:Screen Shot 2021-12-21 at 9.12.03 pm.png]] | |||
* Now we can install the idle3 software by entering the command '''sudo apt-get install idle3''' | |||
* If the software is already installed (as in the example below) the Terminal will tell you. | |||
[[File:Screen Shot 2021-12-21 at 9.14.01 pm.png]] | |||
* If you don’t know what software to install or if the software exists, you can search for software in the library by entering the command '''sudo apt-cache search idle3''' | |||
* If you are interested in installing a game of chess you could enter the command sudo apt-cache search chess or use the wildcard symbol * to expand your search, '''sudo apt-cache search chess*''' | |||
[[File:Screen Shot 2021-12-21 at 9.15.40 pm.png]] | |||
* If the installation of Python3 IDLE has worked correctly you should see the Python3 software link appear in the main Raspberry Pi menu under '''Programming'''. | |||
[[File:Screen Shot 2021-12-21 at 9.16.39 pm.png]] | |||
== Using the python shell to enter code == | |||
* The Python3 Integrated Development and Learning Environment (IDLE) is a common environment for most programming languages. | |||
* Sometimes it is shortened to IDE (Integrated Development Environment). | |||
* These interfaces make editing and running programs easier. Python3 IDLE is very simple and easy to use and it was the first environment installed on the Raspberry Pi for learning Python. | |||
* In this example, we will start using the '''Shell Window'''. | |||
* The Shell Window allows single Python instructions (or small instruction sets) to be entered and tested. | |||
* We will run through a few examples. | |||
=== Explore the Python Shell Window and the Python Language === | |||
* Go to the Python3 IDLE icon in the '''Raspberry Pi > Programming''' menu and open '''IDLE3'''. | |||
* The program will open to the Shell Window. | |||
[[File:Screen Shot 2021-12-21 at 9.18.31 pm.png]] | |||
* We can now start to enter python language instructions directly in the Shell Window. | |||
* Let’s start with some simple arithmetic instructions. Type in '''1 + 3''' and press Enter. | |||
* Try some other operations. | |||
[[File:Screen Shot 2021-12-21 at 9.20.16 pm.png]] | |||
* More complex maths will require some special instructions and the import of additional libraries. | |||
* We will cover this in future lessons. | |||
=== Printing Words, Text and Strings === | |||
* In addition to numbers, we can also print out words and text. | |||
* To make python print out text you enter the command '''print(“Hello”)''' | |||
* In the older days when there were no computer monitors, all output from computers went to printers. | |||
* This legacy continues today, and when we want to display the output from a computer, we use the '''print''' statement. | |||
* To tell a computer that we are working with text we need to include the text in quotation marks '''“Hello”'''. | |||
* Another way we refer to words or text in computer languages, is to call them '''Strings'''. | |||
* Computers manipulate the characters in a word or sentence like beads threaded on a string. Hence the term String. | |||
[[File:Screen Shot 2021-12-21 at 9.22.26 pm.png]] | |||
Revision as of 10:22, 21 December 2021
Overview
- The Python programming language is one of the most universal computer languages used today.
- The makers of the Raspberry Pi though so highly of the language that the name “Pi” was named after Python.
- It is an easy language to learn and will help us to write programs to collect and process data from environmental sensors.
- We will be using the latest version of Python, which is Python3 (Python 3.7.3).
Learning Objectives
- Learn how to install the Python3 Integrated Development and Learning Environment (IDLE3).
- Run python3 code in the Python Shell Window
- Run python programs in the Python Editor Window
Installing Python3 IDLE
- To make programming in Python3 easier we will be using an Integrated Development and Learning Environment (IDLE). * There are many different development environments available for Python.
- Other common environments include: Thonny, PyCharm and iPython.
- In this example we will install the Python3 IDLE using the Terminal on the Raspberry Pi.
- When we need to install programs on the Raspberry Pi we always use the Terminal.
- To install software, we use an application manager called apt.
Installing Python3 IDLE
- Open the Terminal on the Raspberry Pi
- Update our existing software libraries by entering the command sudo apt-get update
- We always need to update our software libraries before we install new software.
- This because software sometimes needs other software to help make it work.
- The additional software components are called dependencies.
- If we install an older version of the software, some of the dependencies may have changed and this could make our program run erratically.
- Now we can install the idle3 software by entering the command sudo apt-get install idle3
- If the software is already installed (as in the example below) the Terminal will tell you.
- If you don’t know what software to install or if the software exists, you can search for software in the library by entering the command sudo apt-cache search idle3
- If you are interested in installing a game of chess you could enter the command sudo apt-cache search chess or use the wildcard symbol * to expand your search, sudo apt-cache search chess*
- If the installation of Python3 IDLE has worked correctly you should see the Python3 software link appear in the main Raspberry Pi menu under Programming.
Using the python shell to enter code
- The Python3 Integrated Development and Learning Environment (IDLE) is a common environment for most programming languages.
- Sometimes it is shortened to IDE (Integrated Development Environment).
- These interfaces make editing and running programs easier. Python3 IDLE is very simple and easy to use and it was the first environment installed on the Raspberry Pi for learning Python.
- In this example, we will start using the Shell Window.
- The Shell Window allows single Python instructions (or small instruction sets) to be entered and tested.
- We will run through a few examples.
Explore the Python Shell Window and the Python Language
- Go to the Python3 IDLE icon in the Raspberry Pi > Programming menu and open IDLE3.
- The program will open to the Shell Window.
- We can now start to enter python language instructions directly in the Shell Window.
- Let’s start with some simple arithmetic instructions. Type in 1 + 3 and press Enter.
- Try some other operations.
- More complex maths will require some special instructions and the import of additional libraries.
- We will cover this in future lessons.
Printing Words, Text and Strings
- In addition to numbers, we can also print out words and text.
- To make python print out text you enter the command print(“Hello”)
- In the older days when there were no computer monitors, all output from computers went to printers.
- This legacy continues today, and when we want to display the output from a computer, we use the print statement.
- To tell a computer that we are working with text we need to include the text in quotation marks “Hello”.
- Another way we refer to words or text in computer languages, is to call them Strings.
- Computers manipulate the characters in a word or sentence like beads threaded on a string. Hence the term String.






