think_python.pdf

(4307 KB) Pobierz
Think
Python
HOW TO THINK LIKE A COMPUTER SCIENTIST
Allen B. Downey
Up
3
on
n
iti
tho
Ed
P y
d
or
2 n
te d f
da
SECOND EDITION
Think Python
Allen B. Downey
Boston
Think Python
by Allen B. Downey
Copyright © 2016 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://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor:
Meghan Blanchette
Production Editor:
Kristen Brown
Copyeditor:
Nan Reinhardt
Proofreader:
Amanda Kersey
August 2012:
December 2015:
First Edition
Second Edition
Indexer:
Allen Downey
Interior Designer:
David Futato
Cover Designer:
Karen Montgomery
Illustrator:
Rebecca Demarest
Revision History for the Second Edition
2015-11-20:
First Release
See
http://oreilly.com/catalog/errata.csp?isbn=9781491939369
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Think Python,
the cover image of a
Carolina parrot, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
Think Python
is available under the Creative Commons Attribution-NonCommercial 3.0 Unported
License. The author maintains an online version at
http://greenteapress.com/thinkpython2/.
978-1-491-93936-9
[LSI]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. The Way of the Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is a Program?
Running Python
The First Program
Arithmetic Operators
Values and Types
Formal and Natural Languages
Debugging
Glossary
Exercises
Assignment Statements
Variable Names
Expressions and Statements
Script Mode
Order of Operations
String Operations
Comments
Debugging
Glossary
Exercises
Function Calls
Math Functions
1
2
3
3
4
5
7
8
9
2. Variables, Expressions and Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
11
12
12
13
14
15
15
16
17
18
21
22
iii
3. Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Zgłoś jeśli naruszono regulamin