concept function in category raspberry pi

appears as: function, functions, function, Functions, The function
Hello Raspberry Pi!: Python programming for kids and other beginners

This is an excerpt from Manning's book Hello Raspberry Pi!: Python programming for kids and other beginners.

Python will answer you: <class 'float'>. You’ve just used Python’s built-in tool for checking the type of something. These built-in tools are called functions. You’ll see more of these later. Let’s see what this does:

In the IDLE 3 text editor, you’ll first load the Python libraries you need, create functions, and prepare your Pi to send electricity to the RGB LED (see figure 7.13).

Figure 7.13. The program starts by importing the Python libraries you’ll need to use, setting up your Pi’s GPIO pins for lighting up the LEDs, and defining the functions you’ll need.

Did you notice that the functions for flashing the LEDs are very similar? Most of the code in each function is the same except for the GPIO pin, so let’s see if you can improve this code to make it simpler. This process of simplifying code is called refactoring.