Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 75
Lists
ОглавлениеA list in Python is an object that is a collection of objects that is referenceable using an index. We create a list object by using an assignment statement in which the right-hand side has multiple values enclosed in square brackets and separated by commas, such as in line 4 of the Python code in Figure 3.1. The list object created on line 4 of Figure 3.1 consists of four objects, the first being a string, the second an integer, the third a float, and the fourth a Boolean-type object. Each of the objects that are in a list can have different data types, which makes working with lists more complex than the previous examples that we have seen that only use more basic Python object data-type variables.
The data within the list in line 4 represent taxi trip information that we will be working with throughout the textbook. We describe this data set in Chapter 1 (see Tables 1.2 and 1.3). The first item is a unique taxi trip ID (here comprising 11 characters, but the real taxi trip IDs in the data set are 40 characters). The second item is a numeric value representing trip seconds—how long the taxi trip took from start to finish. The third item is a numeric value representing trip miles—the distance traveled from the pickup location to the drop-off location of the taxi trip. The fourth item is a Boolean value that might indicate if a customer uses a credit card to pay a fare.