文件名称:
python4everybody.pdf
开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2019-10-07
详细说明:python4everybodyPreface
Remixing an Open Book
It is quite natural for academics who are continuously told to"publish or perish
to want to always create something from scratch that is their own fresh creation
This book is an experiment in not starting from scratch, but instead"remixing
the book titled Think Python: How to Think Like a C
Scientist written
by Allen b. Downey, Jeff Elkner, and others
In December of 2009, i was preparing to teach $1502- Networked Programming at
the University of Michigan for the fifth semester in a row and decided it was time to
write a Python textbook that focused on exploring data instead of understanding
algorithms and abstractions. My goal in SI502 is to teach people lifelong data
handling skills using Python. Few of my students were planning to be professional
computer programmers. Instead, they planned to be librarians, managers, lawyers
biologists, economists, etc, who happened to want to skillfully use technology in
their chosen field
I never seemed to find the perfect data-oriented Python book for my course, So I
set out to write just such a book. Luckily at a faculty meeting three weeks before
I was about to start my new book from scratch over the holiday break, Dr. Atul
Prakash showed me the Think Python book which he had used to teach his Python
course that semester. It is a well-written Computer Science text with a focus on
short, direct explanations and ease of learning
The overall book structure has been changed to get to doing data analysis problems
as quickly as possible and have a series of running examples and exercises about
data analysis from the very beginning
Chapters 2-10 are similar to the Think Python book, but there have been major
changes. Number-oriented examples and exercises have been replaced with data
oriented exercises. Topics are presented in the order needed to build increasingly
sophisticated data analysis solutions. Some topics like try and except are pulled
forward and presented as part of the chapter on conditionals. Functions are given
very light treatment until they are needed to handle program complexity rather
than introduced as an early lesson in abstraction. Nearly all user-defined functions
have been removed from the example code and exercises outside of Chapter 4. The
word"recursion" does not appear in the book at all
In chapters 1 and 11-16, all of the material is brand new, focusing on real-world
uses and simple examples of Python for data analysis including regular expressions
for searching and parsing automating tasks on your computer, retrieving data
across the network, scraping web pages for data, object-oriented programming
using web services, parsing XML and json data, creating and using databases
using Structured Query Language, and visualizing data
The ultimate goal of all of these changes is a shift from a computer Science to an
Informatics focus is to only include topics into a first technology class that can be
useful even if one chooses not to become a professional programmer
l Except, of course, for this line
Students who find this book interesting and want to further explore should look
t Allen B. Downey's Think Python book. Because there is a lot of overlap be-
tween the two books, students will quickly pick up skills in the additional areas of
technical programming and algorithmic thinking that are covered in Think python
And given that the books have a similar writing style, they should be able to move
quickly through Think Python with a minimum of effort
As the copyright holder of Think Python, Allen has given me permission to change
the book's license on the material from his book that remains in this book from the
GNU Free Documentation License to the more recent Creative Commons Attribu-
tie
Share Alike license. This follows a general shift in open documentation
licenses moving from the GFDL to the CC-BY-SA(e.g, Wikipedia). Using the
CC-BY-SA license maintains the book's strong copyleft tradition while making it
even more straightforward for new authors to reuse this material as they see fit
I feel that this book serves an example of why open materials are so important
to the future of education, and want to thank Allen B. Downey and cambridge
University Press for their forward-looking decision to make the book available
under an open copyright. I hope they are pleased with the results of my efforts
and i hope that you the reader are pleased with our collective efforts
I would like to thank Allen B. Downey and Lauren Cowles for their help, patience
and guidance in dealing with and resolving the copyright issues around this book
Charles severance
www.dr-chuck.com
Ann arbor. MI. USA
September 9, 2013
Charles Severance is a Clinical Associate Professor at the University of Michigan
School of information
Contents
Why should you learn to write programs
1.1 Creativity and motivation
1.2 Computer hardware architecture
1.3 Understanding programming
1.4 Words and sentences
1.5 Conversing with Python
234568
1.6 Terminology: interpreter and compiler
1.7 Writing a program
10
1. 8 What is a program
1. 9 The building blocks of programs
1. 10 What could possibly go wrong?
12
1.11 The learning journey
14
1. 12 Glossary
14
1.13 Exercises
16
2 Variables, expressions, and statements
2.1 Values and types
2.2 Variables
2.3 Variable names and keywords
21
2. 4 Statements
21
2.5 Operators and operands
2
2.6 Expressions
23
2.7 Order of operations
23
2. 8 Modulus operator
2.9 String operations
24
2.10 Asking the user for input
25
CONTENTS
2. 11 Comments
26
2. 12 Choosing mnemonic variable names
2.13 Debugging
2. 14 Glossary
2.15 Exercises
30
3 Conditional execution
33
3.1 Boolean expressions
33
3.2 Logical operators
34
3.3 Conditional execution
34
3.4 Alternative execution
35
3.5 Chained conditionals
3.6 Nested conditionals
37
3.7 Catching exceptions using try and except
38
3.8 Short-circuit evaluation of logical expressions
40
3.9 Debugging
3.10 Glossary
3.11 Exercises
42
4 Functions
45
4.1 Function calls
45
4.2 Built-in functions
4.3T
ype conversion functions
46
4.4 Math functions
47
4.5 Random numbers
48
4.6 Adding new functions
4.7 Definitions and uses
50
4. 8 Flow of execution
51
4.9 Parameters and arguments
4.10 Fruitful functions and void functions
53
4. 11 Why functions?
54
4.12 Debugging
54
4.13 Glossary
55
4.14 Exercises
56
CONTENTS
5 teration
59
5.1 Updating variables
59
5.2 The while statement
59
5.3 Infinite loops
5.4“ Infinite loops” and break
5.5 Finishing iterations with continue
61
5.6 Definite loops using for
5.7 Loop patterns
5.7.1 Counting and summing loops
5.7.2 Maximum and minimum loops
64
5. 8 Debugging
5.9 Glossary
66
5.10 Exercises
6 Strings
69
6.1 A string is a sequence
6.2 Getting the length of a string using len
70
6.3 Traversal through a string with a loop
6.4 String slices
6.5 Strings are immutable
6.6 Looping and counting
72
6. 7 The in operator
6.8 String comparison
6.9 string methods
73
6.10 Parsing strings
76
6.11 Format operator
6. 12 Debugging
77
6. 13 Glossary
78
6.14 Exercises
7 Files
81
7.1 Persistence
81
7.2 Opening files
82
7.3 Text files and lines
83
7.4 Reading files
CONTENTS
7.5 Searching through a file
7.6 Letting the user choose the file name
7.7 Using try, except, and open
7.8 Writing files
7.9 Debugging
90
7.10 Glossary
7.11 Exercises
8 Lists
93
8.1 A list is a sequence
93
8.2 Lists are mutable
94
8.3 Traversing a list
94
8.4 List operations
8.5 List slices
8.6 List methods
8.7 Deleting elements
97
8. 8 Lists and functions
98
8.9 Lists and strings
99
8.10 Parsing lines
100
11 Objects and values
101
8.12 Aliasing
102
8.13 List arguments
8. 14 Debugging
104
8.15 Glossary
107
8. 16 Exercises
108
9 Dictionaries
111
9.1 Dictionary as a set of counters
113
9.2 Dictionaries and files
114
9.3 Looping and dictionaries
115
9.4 Advanced text parsing
117
9.5 Debugging
118
9.6 Glossary
119
9. 7 Exercises
.120
CONTENTS
10 Tuples
121
10.1 Tuples are immutable
121
10.2 Comparing tuples
122
10.3 Tuple assignment
124
10.4 Dictionaries and tuples
125
10.5 Multiple assignment with dictionaries
126
10.6 The most common words
127
10.7 Using tuples as keys in dictionaries
128
10.8 Sequences: strings, lists, and tuples-Oh M:
128
10.9 Debugging
129
10.10Glossary
10. 1 1 Exercises
131
11 Regular expressions
133
11.1 Character matching in regular expressions
134
11.2 Extracting data using regular expressions
.135
11.3 Combining searching and extracting
11.4 Escape character
141
1.5 Summary
142
11.6 Bonus section for Unix/ Linux users
143
11.7 Deb
ugging
143
oSSary
144
1.9 Exercises
145
12 Networked programs
147
12.1HypertextTransferProtocol-http
.147
12.2 The Worlds Simplest Web Browser
12.3 Retrieving an image over Http
149
12.4 Retrieving web pages with urllib
152
12.5 Parsing HTML and scraping the web
153
12.6 Parsing HTML using regular expressions
12.7 Parsing HTML using BeautifulSoup
154
12.8 Reading binary files using urllib
156
12.9 Glossary
158
12.10Exercises
158
CONTENTS
13 Using Web Services
161
13.1 eXtensible Markup Language-XML
161
13.2 Parsing XML
162
13.3 Looping through nodes
163
13.4 JavaScript Object Notation-JSON
164
13.5 Parsing JSON
164
13.6 Application Programming Interfaces
165
13.7 Google geocoding web service
167
13.8 Security and API usage
169
13.9 Glossary
174
13. 10Exercises
174
14 Object-Oriented Programming
175
14.1 Managing Larger Programs
175
14.2 Getting Started
176
14.3 Using Objects
176
14.4 Starting with Programs
177
14.5 Subdividing a Problem -Encapsulation
179
14.6 Our First Python Object
180
14.7 Classes as Types
182
14.8 Object Lifecycle
.183
14.9 Many Instances
184
14.10Inheritance
185
14.11Summary
186
14. 12Glossary
187
15 Using Databases and SQL
189
15.1 What is a database?
189
15.2 Database concepts
189
15.3 Database Browser for SQLite
190
15.4 Creating a database table
190
15.5 Structured Query Language summary
193
15.6 Spidering Twitter using a database
195
15. 7 Basic data modeling
200
15.8 Programming with multiple tables
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.