We will write a simple Python program that contains a class. To facilitate this, we will use Thonny, a Python IDE that comes pre-installed with Raspbian and has excellent debug and variable introspection functionalities. You will find that its ease of use makes it ideal for the development of our projects.
We will begin our program by creating a class. A class may be seen as a template for creating objects. A class contains methods and variables. To create a class in Python with Thonny, do the following:
- Load Thonny through
Application Menu
|Programming
|Thonny
. SelectNew
from the top left and type the following code:
class CurrentWeather: weather_data={'Toronto':['13','partly sunny','8 km/h NW'], 'Montreal':['16','mostly sunny','22 km/h W'], 'Vancouver':['18','thunder showers','10 km/h NE'], 'New York':['17','mostly cloudy','5 km/h SE'], 'Los Angeles':['28','sunny','4 km/h SW'], ...