开发工具:
文件大小: 2mb
下载次数: 0
上传时间: 2019-03-08
详细说明:较为全面的python教程,零基础小白进阶,基础操作知识出发学习python。Preface
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"remixin
the book titled Think Python: How to Think like a Computer 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 $I502 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
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 increasingl
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 to shift from a Computer Science to an
Informatics focus and to only include topics into a first technology class that can
be useful even if one chooses not to become a professional programmer
Except, of course, for this line
Students who find this book interesting and want to further explore should look
at 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
tion- Share Alike license. This follows a general shift in open documentation
licenses moving from the GFDl to the CC-BY-SA(. g, Wikipedia). US
SIn
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 as an example of why open materials are so important
to the future of education, and i 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
1 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
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 Debugging
1.12 The learning journey
1.13 Glossary
15
1.14 Exercises
2 Variables, expressions, and statements
19
2.1 Values and types
19
2.2 Variables
20
2.3 Variable names and keywords
21
2.4 Statements
21
2.5 Operators and operands
22
2.6 Expressions
23
2.7 Order of operations
23
2.8 Modulus operator
24
2.9 String operations
24
CONTENTS
2.10 Asking the user for input
25
2.11 Comments
26
2.12 Choosing mnemonic variable names
27
2. 13 Debugging
2.14 Glossary
2.15 Exercises
30
3 Conditional execution
31
3.1 Boolean expressions
3.2 Logical operators
32
3.3 Conditional execution
32
3.4 Alternative execution
33
3.5 Chained conditionals
34
3.6 Nested conditionals
35
3.7 Catching exceptions using try and except
36
3.8 Short-circuit evaluation of logical expressions
3.9 Debugging
39
3.10 Glossary
39
3.11 Exercises
4 Functions
43
4.1 Function calls
43
4.2 Built-in functions
43
4.3 Type conversion functions
44
4.4 Math functions
4.
Random numbers
46
4.6 Adding new functions
47
4.7 Definitions and uses
48
4.8 Flow of execution
49
4.9 Parameters and arguments
49
4.10 Fruitful functions and void functions
4.11 Why functions?
52
4.12D
Debugging
52
4.13 Glossary
53
4.14 Exercises
54
CONTENTS
5 Iteration
57
5.1 Updating variable
57
5.2 The while statement
57
5.3 Infinite lo
58
Infinite lo
d break
5.5 Finishing iterations with continue
59
5.6 Definite loops using for
5.7 Loop patterns
61
5.7.1 Counting and
g loop
5.7.2 Maximum and minimum loops
62
58
Debugging
64
5.9 Glo
ssary
64
5.10 Exercises
64
6 Strings
67
6.1 A string is a sequence
6.2 Getting the length of a string using len
6.3 Traversal through a string with a loop
6.4 String slices
6.5 Strings are immutable
70
6.6 Looping and counting
70
6.7 The in operator
6. 8 String comparison
6.9 string methods
6.10 Parsing strings
74
6.11 Format operator
74
6.12 Debugging
75
6.13 Glossary
76
6.14 Exercises
77
7 Files
79
7.1 Persistence
79
7. 2 Opening files
7. 3 Text files and lines
7.4 Reading files
CONTENTS
7.5 Searching through a file
83
7.6 Letting the user choose the file name
7.7 Using try, except, and open
86
7.8 Writing files
87
7.9 Debugging
7.10 Glossary
7.11 Exercises
8 Lists
91
8.1 A list is a sequence
2 Lists are mutable
92
8.3 Traversing a list
92
4 List operations
93
List slices
8.6 List methods
94
8.7 Deleting elements
8. 8 Lists and functions
96
8.9 Lists and strings
97
8.10 Parsing lines
98
8.11 Objects and values
99
8.12 Aliasing
100
8.13 List arguments
8.14 Debugging
102
8.15 losser
8.16 Exercises
105
9 Dictionaries
107
9.1 Dictionary as a set of counters
..109
9.2 Dictionaries and files
110
9.3 Looping and dictionaries
.,,111
9.4 Advanced text parsing
113
9.5 Debugging
114
9.6 Glossary
115
9. 7 Exercises
115
CONTENTS
10 Tuples
117
10.1 Tuples are immutable
10.2 Comparing tuples
118
10.3 Tuple assignment
120
10.4 Dictionaries and tuples
121
10.5 Multiple assignment with dictionaries
122
10.6 The most common words
123
10.7 USing tuples as keys in dictionaries
124
10.8 Sequences: strings, lists, and tuples -Oh My!
124
10.9 Debugging
125
10.10 Glossary
125
10.11 Exercises
126
1 Regular expressions
127
11.1 Character matching in regular expressions
128
11.2 Extracting data using regular expressions
129
11.3 Combining searching and extracting
132
11.4 Escape character
136
11.5 Summary
136
11.6 Bonus section for Unix/ Linux users
.137
11. 7 Debugging
138
11.8 Glossary
138
11.9 Exercises
139
12 Networked programs
141
12.1HypertextTransferProtocol-http
141
12.2 The World's Simplest Web Browser
.142
12.3 reTrieving an image over Http
144
12. 4 Retrieving web pages with urllib
146
12.5 Reading binary files using urllib
147
12.6 Parsing HTML and scraping the web
148
12.7 Parsing HTML using regular expressions
148
12.8 Parsing HTML using BeautifulSoup
150
12.9 Bonus section for Unix/Linux users
153
12.10 Glossary
153
12.11 Exercises
154
CONTENTS
13 USing Web services
155
13.1 eXtensible Markup Language-XML
155
13.2 Parsing XML
156
13.3 Looping through nodes
157
13.4 JavaScript Object Notation - JSON
158
13.5 Parsing JSON
158
13.6 Application Programming Interfaces
159
13.7 Google geocoding web service
161
13.8 Security and API usage
163
13.9 Glossary
168
13.10 Exercises
168
14 Object-Oriented Programming
169
naging larger programs
169
4.2 Getting Sta
170
14.3 USing Objects
170
14.4 Starting with Programs
171
14.5 Subdividing a Problem- Encapsulation
173
14.6 Our First Python Object
174
14.7Cl
176
14.8 Object Lifecycle
177
14.9 Many Instances
178
L4.10 Inheritance
179
14.11 Summary
180
14.12 Glossary
181
15 Using Databases and SQL
183
15.1 What is a database?
183
15.2 Database concepts
183
15.3 Database Browser for SQLite
184
15.4 Creating a database table
184
15.5 Structured Query Language summary
..187
15.6 Spidering Twitter using a database
189
15.7 Basic data modeling
194
15.8 Programming with multiple tables
195
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.