A Byte of Python
Tags
Summary
A Byte of Python is the simplified Chinese translation of the free English book A Byte of Python, written by Swaroop C. H. and translated by Shen Jieyuan. Written as both textbook and guide, the book takes readers from zero foundation—from "being able to save a text file"—to writing small Python programs independently. It begins with what Python is and its place in the open-source world, then introduces installing Python on Linux/BSD and Windows, the interpreter and editors, source files and executable programs, and other first hands-on steps; it then proceeds in turn to basic concepts (numbers, strings, variables, identifiers, data types, objects, logical and physical lines, indentation), operators and expressions with their precedence and associativity, control flow (if, while, for, break, continue), functions (parameters, local variables, global, default arguments, keyword arguments, return, DocStrings), modules (sys, .pyc byte compilation, from...import, a module's __name__, writing your own modules), and data structures including lists, tuples, dictionaries, sets, sequences, and strings. Later it demonstrates problem solving and the software development process through repeated iterations of a script, and explains object-oriented programming (self, classes, object methods, __init__, class and object variables, inheritance), input and output (user input, files, pickle), exception handling and the standard library, and finally offers directions for further study and an appendix on free and open-source software (FLOSS). Concise in length, dense with examples, and plain in language, the book has been widely regarded since publication as a small introductory book for Python beginners.
Editor's review
很多 Python 入门书厚得像砖头,这本书薄得让人怀疑它能不能讲完。事实是它讲完了:从解释器怎么打开,到类、继承、文件读写、异常处理和标准库,两百页不到就把一门语言的骨架交待清楚。作者 Swaroop C. H. 原本就是为「只会保存文本文件」的读者写的,所以每个概念都配有可以直接照着敲的示例和「它如何工作」的拆解,读完一段代码立刻能跑出结果,成就感来得快,挫败感来得少。译者在翻译时与作者逐条讨论过原书不清楚的地方,还为书中示例配齐了源代码、在书后附上中英对照术语表,方便读者之后去啃英文文档。它不追求面面俱到,也不适合当作查阅型手册,但作为「第一本 Python 书」非常称职:短、顺、便宜(甚至有免费电子版可对照)。如果你打算先花一个周末确认自己是否喜欢编程,这本书比任何大部头都更合适。
Who it's for
A good fit for
- 零基础、第一次接触编程,想低成本试探自己是否适合写代码的人
- 有其他语言经验(如 C、Java、JavaScript),想快速上手 Python 语法的程序员
- 需要给学生或团队新人准备一份短小入门讲义的高校教师与团队负责人
- 偏好薄书、想先建立整体认知再深入某个方向的自学者
Not a good fit for
- 已有 Python 使用经验、想系统深入学习语言细节与惯用法的读者
- 希望查阅完整标准库、第三方生态或工程实践的大型参考书需求者
- 以数据分析、Web 开发、机器学习等具体方向应用为直接目标的读者
Reading tips
- 务必边读边敲:每章的示例先照抄运行,再改参数观察输出差异,效果远胜只读不写。
- 安装 Python 3 环境后再开始,书中的 Python 2 相关内容可只做了解、不必深究。
- 可以配合官方电子版与书中附录的术语表使用,遇到中英术语不一致时以英文原词为线索查文档。
- 读完后不要停在书上,立刻挑一个小需求(如批量重命名文件、抓取网页标题)独立做完。
Contents
- Preface (Who This Book Is For, History Lesson, Official Website, Conventions, Feedback)
- Chapter 1 Introduction (Introduction, Features of Python, Summary, Why Not Perl, Programmers' Words)
- Chapter 2 Installation (For Linux and BSD Users, For Windows Users)
- Chapter 3 First Steps (Using the Prompted Interpreter, Choosing an Editor, Using a Source File, Executable Python Programs, Getting Help)
- Chapter 4 The Basics (Literal Constants, Numbers, Strings, Variables, Identifier Naming, Data Types, Objects, Logical and Physical Lines, Indentation)
- Chapter 5 Operators and Expressions (Operators, Operator Precedence, Order of Evaluation, Associativity, Expressions)
- Chapter 6 Control Flow (The if Statement, The while Statement, The for Loop, The break Statement, The continue Statement)
- Chapter 7 Functions (Defining Functions, Function Parameters, Local Variables, The global Statement, Default Argument Values, Keyword Arguments, The return Statement, DocStrings)
- Chapter 8 Modules (Using the sys Module, Byte-compiled .pyc Files, The from...import Statement, A Module's __name__, Making Your Own Modules)
- Chapter 9 Data Structures (Lists, Tuples, Dictionaries, Sequences, Sets, References, More on Strings)
- Chapter 10 Problem Solving—Writing a Python Script (The Problem, The First through Fourth Versions of the Solution, More Improvements, The Software Development Process)
- Chapter 11 Object-Oriented Programming (self, Classes, Object Methods, The __init__ Method, Class and Object Variables, Inheritance)
- Chapter 12 Input and Output (User Input, Files, Pickle)
- Chapter 13 Exceptions (Errors, Exceptions, Handling Exceptions, Raising Exceptions, try...finally, The with Statement)
- Chapter 14 The Python Standard Library (The sys Module, The logging Module, The Weekly Module Series)
- Chapter 15 More Python (Passing Tuples, Special Methods, Single Statement Blocks, The lambda Form, List Comprehensions, Receiving Tuples and Dictionaries in Functions, The assert Statement, Escape Sequences and Raw Strings)
- Chapter 16 What Next? (Example Code, Questions and Answers, Tutorials, Videos, Discussion, News, Installing Libraries, Graphical Software, Various Implementations)
- Appendix A Free and Open Source Software (FLOSS)
- Appendix B About the Book (History and Revision History, About the Translation)
- Appendix C Revision Record and Glossary
FAQ
这本书讲的是 Python 2 还是 Python 3?
不同版本差异较大。早期中文译本(2005 年沈洁元据 1.20 版翻译)以 Python 2 为主;2017 年漠伦据原书 4.0 版重新翻译的译本则以 Python 3 为主,并说明如何兼顾 Python 2。购买或下载前请先确认版本。
这本书有正式出版的中文纸质版吗?
《A Byte of Python》中文译名即《简明 Python 教程》,流传较广的版本是 Lulu Marketplace 出版的英文版附中文副标题(ISBN 9789577296467,2008 年)。国内读者更多是通过作者官网与译者发布的免费电子版阅读,购买前建议核实版本来源。
书很薄,内容会不会太浅?
定位就是入门 tutorial:覆盖语法主干、模块、数据结构、面向对象、文件与异常、标准库概览,足以写出小脚本并向进阶材料过渡。它不深入 CPython 内部机制,也不完整覆盖标准库,进阶需另配读物。
电子版是免费的吗?
原书以自由图书形式发布,英文版可在作者网站 python.swaroopch.com 在线阅读,中文译本也有译者授权发布的电子版与社区整理的 Markdown 版。纸质版或第三方渠道文件请留意版权与来源。
读完这本书之后该读什么?
可以先做一两个完整小项目巩固,再按方向选择:语言进阶可读《流畅的Python》,数据处理读《利用Python进行数据分析》,工程实践读官方文档与《Python Cookbook》,也可参考书中「接下来学习什么」一章的资源清单。
Comments
Find this book
This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.