OReilly Think Python (2012).pdf

(7696 KB) Pobierz
994563950.001.png
Think Python
Allen B. Downey
994563950.002.png
Think Python
by Allen B. Downey
Copyright © 2012 Allen Downey. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles ( http://my.safaribooksonline.com ) . For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editors: Mike Loukides and Meghan Blanchette
Production Editor: Rachel Steely
Proofreader: Stacie Arellano
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrators: Robert Romano and Rebecca Demarest
August 2012:
First Edition
Revision History for the First Edition:
2012-08-03
First release
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc. Think Python , the image of a Carolina Parrot, and related trade dress are trademarks of O’Reilly
Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade­
mark claim, the designations have been printed in caps or initial caps.
The author maintains an online version at http://thinkpython.com/thinkpython.pdf .
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-33072-9
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1.
The Way of the Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
The Python Programming Language 1
What Is a Program? 3
What Is Debugging? 4
Syntax Errors 4
Runtime Errors 4
Semantic Errors 5
Experimental Debugging 5
Formal and Natural Languages 6
The First Program 7
Debugging 8
Glossary 9
Exercises 11
2.
Variables, Expressions, and Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Values and Types 13
Variables 14
Variable Names and Keywords 15
Operators and Operands 16
Expressions and Statements 16
Interactive Mode and Script Mode 17
Order of Operations 18
String Operations 18
Comments 19
Debugging 19
Glossary 20
iii
994563950.003.png
 
Zgłoś jeśli naruszono regulamin