Learn to program with Python 3 and the Raspberry Pi, introductory course.
ⓘ This article may have been partially or fully translated using automatic tools. We apologize for any errors this may cause.
We know that many of our readers want to learn how to code and build their own software for Raspberry Pi, but don't know how or where to start.
That's good, the Raspberry Pi was invented to allow everyone to learn to program!
Thanks to this tutorial, you will be able to learn the basics of Python, which will allow you to create simple software, in particular to control equipment connected to the Raspberry Pi.
The material needed for this Python course
To take this course, you will simply need the following materials:
You will also need to be able to control your Raspberry Pi, either via screen / keyboard, or remotely in SSH (see our tutorial on the subject).
Who is this course for?
This course is more for beginners. It does not go into the details of a very advanced use of Python, but it will allow you to discover the basics of this language.
The knowledge thus acquired should still allow you to carry out most of the programs you may need, but also give you the basics allowing you to acquire additional knowledge on your own.
This course was originally created with the aim of being given to a class of first year computer science students, in order to introduce them to Python over an hourly volume of approximately 8 hours.
This course has been designed with a view to serving as a presentation support that will be distributed at the end of the session in order to allow the students to use it as a complete review sheet. You will also see some sentences relating to this type of presentation, such as the group formation rules, we leave them for any teachers who would like to be inspired by them.
If you need to train people to use Python, especially in the Digital and Computer Science specialties, etc., you can reuse this presentation without any rights issues!
We only ask that you cite the source of the course!
Python points seen in this course
In this course, you will find the following topics covered:
- Overview of Python, its history and use
- Installation of the development environment
- Discover the Python shell
- Create a first Python script
- Use variables and read user values
- Understand the notion of types in Python
- Manipulate and display text
- Use mathematical operators
- Use conditions in your programs
- Repeat actions with loops
- Re-use code with functions
- Find and use others' code with the Python and Pip libraries
- Cut your program with "import"
- Reading and writing files with Python
- Running Linux commands with Python
- Connect Python to a Database and Use MySQL
- Exercise, create a Python program that uses an API
- The best places to find help with Python
This course introduces the use of computer basics, such as variables, but since it is intended for students who already have some programming basics, their interest is not always covered in detail.
Here is a small glossary to help you understand the interest of these basic concepts.
- Variable: A way to associate a unique name that does not change with a value that can change. For example, to store the number of turns of a game, which will evolve gradually, under the name "number_turn", to find it easily.
- Loop: A way to repeat an action without having to write it multiple times in the program. For example, display 1, 2, 3 …, 1000, without actually having to type 1000 times the command used to display.
- Condition: A way to have part of the program executed only if certain conditions are met. For example, display 1, 2, 3 …, 1000, but display the number in red, ONLY if it is greater than 5 and less than 10.
- Types: Characterize the content of a variable in order to know if it contains numbers, text, a value of type true or false, an array of values, etc.
- Functions: A way of grouping a portion of code under a unique name to be able to call it easily without having to rewrite it. For example, if we turn on often when we see, we will create a function for that, which we will call each time, rather than retyping the same complicated code all the time.
- A library: A set of functions which deal with the same subject, for example sending e-mail, and which have been grouped together so that they can be easily used and integrated into any program.
Introduction to Python with the Raspberry Pi
You can find this course in full screen at the following address: https://raspberry-pi.fr/cours/slides-python-introduction.html
Want to go further with Python, need a more complete tutorial? Check out our partner Éléphorm's course to learn Python!
You can also get Patrice Clément's book "Python and Raspberry pi".