Skip to Content
Python数据处理
book

Python数据处理

by Jacqueline Kazil, Katharine Jarmul
July 2017
Intermediate to advanced
398 pages
11h 54m
Chinese
Posts & Telecom Press
Content preview from Python数据处理
Python
基础
21
>>>recipe
"A recipe isn't just a list of ingredients."
变量的数据类型不一定要是字符串或整数。变量可以保存各种不同的
Python
数据类型,我
们会在后续章节进一步学习这方面的内容。
2.2.2
 列表
列表是具有某种共同关系的一组值。在
Python
中使用列表,和在日常语言中使用列表很相
似。在
Python
中,将一列元素放到方括号(
[]
)中,元素之间用逗号隔开,即可创建列表。
我们在
Python
中创建一个食品的列表:
['milk', 'lettuce', 'eggs']
上面这个列表由字符串组成,不是由变量组成。这一点是可以看出来的,因
为单词都用引号包裹。如果元素都是变量的话,是不会有两边的引号的。
按下
Return
键,
Python
会返回以下内容:
['milk', 'lettuce', 'eggs']
你刚刚创建了第一个
Python
列表:字符串列表。你可以创建任意数据类型的列表,或者多
种数据类型混合的列表(例如,同时包含浮点数和字符串的列表)。我们来创建一个同时
包含整数和浮点数的列表:
[0, 1.0, 5, 10.0]
下面将我们的列表保存在变量中,这样就可以在后面的代码中调用它。变量很有用,因为
变量可以让我们不必反复输入数据。如果列表很长,比如说有
5000
个元素那么长,手动
输入数据很容易出错,而且效率不高。正如前文所述,变量是保存值的方法,将其保存在
合理命名的容器中。
Python
解释器中尝试以下代码:
shopping_list ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

数据科学中的实用统计学(第2版)

数据科学中的实用统计学(第2版)

Peter Bruce, Andrew Bruce, Peter Gedeck
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez
解密金融数据

解密金融数据

Justin Pauley

Publisher Resources

ISBN: 9787115459190