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数据处理
361
附录E
Python
陷阱
同你学习的其他语言一样,
Python
也有它的怪癖和特点。其中一些特点是脚本语言共有
的,如果你有脚本语言的经验,可能不会感到惊讶。其他的特点是
Python
独有的。我们总
结了其中一些特点,但并不完全,所以你可以自己去了解更多。我们希望本附录可以帮助
你调试代码,也能让你了解
Python
行为方式的原因。
E.1
 空白
可能你已经注意到,
Python
使用空白作为代码结构的一部分。空白被用来缩进函数、方法
和类;去执行
if-else
语句;创建持续的代码行。在
Python
中,空白是一种特殊的操作符,
能帮助转化
Python
代码为可执行的代码。
下面是
Python
文件中空白的一些最佳实践。
不要使用
tab
,使用空格。
对于每一个缩进块,使用
4
个空格。
为悬挂式缩进选择一种好的缩进策略(可以通过一个分隔符、一个额外的缩进或一个
单个缩进对齐,但是必需选用可读性和实用性最好的方式;参见
PEP-8
https://www.
python.org/dev/peps/pep-0008/#indentation
)。
PEP-8
(或
Python
增强方案
#8
)是一个
Python
风格指南,给出了缩进的最
佳实践,并针对如何命名变量、代码行换行、格式化代码提出了建议,让代
码可读、易于使用、易于分享。
如果你的代码没有正确地缩进,并且
Python
不能解析你的文件,你会得到一个
IndentationError
。错误信息会告诉你哪一行代码没有正确缩进。在你最喜欢的文本编辑
器中设置
Python
的语法提示器是相当简单的,以便在你工作时自动检查你的代码。举个例 ...
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