Basic elements of Python¶
In this lesson we will revisit data types, learn how data can be stored in Python lists, and about the concept of objects in programming. If you have not already started Spyder you should do so now. You can find directions on how to open Spyder at the start of Lesson 1.
Sources¶
Like the previous lesson, this lesson is inspired by the Programming with Python lessons from the Software Carpentry organization.
Data types revisited¶
We saw a bit about variables and their values in the lesson last week, and we continue today with some variables related to FMI observation stations in Finland. For each station, a number of pieces of information are given, including the name of the station, an FMISID, its latitude, its longitude, and the station type. We can store this information and some additional information for a given station in Python as follows:
In [1]: stationName = 'Helsinki Kaivopuisto' In [2]: stationID = 132310 In [3]: stationLat = 60.15 In [4]: stationLong = 24.96 In [5]: stationType = 'Mareographs'
Here we have 5 values assigned to variables related to a single observation station. Each variable has a unique name and they can store different types of data.
We can explore the different types of data stored in variables using the
type()
function.In [6]: type(stationName) Out[6]: str In [7]: type(stationID)