"Python programming: from getting started to practicing" [Eric Matthes] Chinese PDF non-scanned version

Source: Internet
Author: User
Tags delete key using git virtual environment heroku toolbelt

: Network disk Download Content Introduction· · · · · ·

This book is an introductory Python book for all levels of Python readers. The book is divided into two parts: the first part introduces the basic concepts that you must understand in Python programming, including powerful Python libraries and tools such as Matplotlib, NumPy, and Pygal, as well as lists, dictionaries, if statements, classes, files and exceptions, code testing, and more The second part puts the theory into practice and explains how to develop three projects, including simple Python 2D game development How to use data to generate interactive infographic, create and customize simple Web applications, and help readers solve common programming problems and puzzles.

about the author· · · · · ·

Author Profile:

Eric Matthes

Senior High school science and math teacher, now residing in Alaska, teaches a local python introductory course. He has been writing programs since he was 5 years old.

Translator Profile:

Ching

Freelance translator; 2000 Professional translation, master translation of books, occasional translation of press releases, soft articles, published translations of 40 more than, including the C + + Prime plus Chinese version of the CCNA Learning Guide, CCNP Route Learning Guide, model-oriented Software architecture: Model system Android App UI design mode "VC choice: Who is the next 1 billion-dollar company," and so on, a total of more than 7 million words; Before the professional translation, engaged in three years of chemical product analysis and development, has done two years magazine and book editor.

Catalogue· · · · · · The first part of the basic knowledge
The 1th Chapter starts 2
1.1 Setting up the programming environment 2
1.1.1 Python 2 and Python 3 2
1.1.2 Running Python code snippet 3
1.1.3 Hello World Program 3
1.2 Setting up a Python programming environment in different operating systems 3
1.2.1 Setting up a python programming environment in a Linux system 3
1.2.2 Building a Python programming environment in OS X systems 6
1.2.3 setting up a python programming environment in a Windows system 8
1.3 Troubleshooting Installation Issues 12
1.4 Running a Python program from a terminal 13
1.4.1 running Python programs from the terminal in Linux and OS X systems 13
1.4.2 running a python program from a terminal in a Windows system 13
1.5 Summary 14
Chapter 2nd variables and simple data types 15
2.1 What happens when you run hello_world.py 15
2.2 Variables 16
Naming and using the 2.2.1 variable 16
2.2.2 Avoid naming errors when using variables 17
2.3 String 18
2.3.1 using methods to modify the case of a string 19
2.3.2 Merging (stitching) strings 19
2.3.3 Add a blank by using tabs or newline characters 20
2.3.4 Delete blank 21
2.3.5 Avoid syntax errors when using strings 22
2.3.6 The print statement in Python 2 23
2.4 Number 24
2.4.1 Integer 24
2.4.2 Floating point 25
2.4.3 using function str () to avoid type error 25
2.4.4 integer 26 in Python 2
2.5 Notes 27
2.5.1 How to write comments 27
2.5.2 What kind of notes should be written 28
2.6 Python Zen 28
2.7 Summary 30
3rd. Introduction to the list 31
3.1 What is the list 31
3.1.1 Access list Element 32
3.1.2 Index starting from 0 instead of 1 32
3.1.3 using each of the values in the list 33
3.2 Modifying, adding, and deleting elements 33
3.2.1 Modifying a list element 34
3.2.2 Adding elements to the list 34
3.2.3 removing elements from the list 35
3.3 Organization List 39
3.3.1 using the method sort () to sort a list permanently 39
3.3.2 using the function sorted () to sort the list temporarily 40
3.3.3 Backwards Print List 41
3.3.4 determining the length of a list 41
3.4 Avoiding Index errors when using lists 42
3.5 Summary 43
4th Operation List 44
4.1 Traversing the entire list 44
4.1.1 in-depth study cycle 45
4.1.2 performing more actions in the For Loop 46
4.1.3 perform some actions after the for Loop 47
4.2 Avoiding Indentation Error 47
4.2.1 Forget to indent 48
4.2.2 Forget to indent extra lines of code 48
4.2.3 Unnecessary indentation 49
4.2.4 unnecessary indentation after Loop 49
4.2.5 omitted the colon 50
4.3 Creating a value List 51
4.3.1 using function range () 51
4.3.2 using range () to create a list of numbers 51
4.3.3 perform simple statistical calculations on a list of numbers 53
4.3.4 List resolution 53
4.4 Using part of the list 54
4.4.1 Slicing 54
4.4.2 traversing slices 56
4.4.3 Copy List 56
4.5 RMB Group 59
4.5.1 Defining tuples 59
4.5.2 traversing all values in tuples 59
4.5.3 Modifying tuple variables 60
4.6 Setting the Code format 61
4.6.1 Format Setup Guide 61
4.6.2 Indent 61
4.6.3 President 61
4.6.4 Blank Line 62
4.6.5 Other formatting Guides 62
4.7 Summary 63
5th. If statement 64
5.1 A simple example 64
5.2 Piece Test 65
5.2.1 Check for Equality 65
5.2.2 Check if equality is not considered case 65
5.2.3 Check for unequal 66
5.2.4 Comparison Number 67
5.2.5 checking Multiple conditions 67
5.2.6 Check if a specific value is included in the list 68
5.2.7 Check if a specific value is not included in the list 69
5.2.8 Boolean expression 69
5.3 If Statement 70
5.3.1 Simple If statement 70
5.3.2 If-else Statement 71
5.3.3 If-elif-else Structure 72
5.3.4 using multiple elif code blocks 73
5.3.5 omitting the Else code block 74
5.3.6 testing Multiple conditions 74
5.4 Using the IF statement to process a list 76
5.4.1 Checking for special elements 77
5.4.2 determine that the list is not empty 78
5.4.3 Using multiple lists 78
5.5 Format The IF statement 80
5.6 Summary 80
6th Chapter Dictionary 81
6.1 A simple dictionary 81
6.2 Using a dictionary 82
6.2.1 Accessing the value in the dictionary 82
6.2.2 Adding a key-value pair 83
6.2.3 Create an empty dictionary first 83
6.2.4 Modifying a value in a dictionary 84
6.2.5 Delete key-value pair 85
6.2.6 dictionary consisting of similar objects 86
6.3 Traversing the dictionary 87
6.3.1 traversal of all key-value pairs 87
6.3.2 traversing all keys in the dictionary 89
6.3.3 to traverse all keys in the dictionary sequentially 91
6.3.4 traversing all values in the dictionary 91
6.4 Nesting 93
6.4.1 Dictionary List 93
6.4.2 storing lists in a dictionary 95
6.4.3 storing dictionaries in a dictionary 97
6.5 Summary 99
Chapter 7th user input and while loop 100
7.1 How function input () works 100
7.1.1 writing a clear program 101
7.1.2 using int () to get numeric input 102
7.1.3 modulo operator 103
7.1.4 get input 104 in Python 2.7
7.2 While loop Introduction 104
7.2.1 using while loop 104
7.2.2 Let the user choose when to exit 105
7.2.3 using Flag 106
7.2.4 using break to exit the Loop 107
7.2.5 using continue 108 in loops
7.2.6 Avoid infinite loops 109
7.3 Working with a while loop to work with lists and dictionaries 110
7.3.1 moving elements between lists 110
7.3.2 Delete all list elements that contain a specific value 111
7.3.3 using user input to populate the dictionary 112
7.4 Summary 113
8th Chapter Function 114
8.1 Defining a function 114
8.1.1 passing information to a function 115
8.1.2 arguments and formal parameters 115
8.2 Passing Arguments 116
8.2.1 positional Argument 116
8.2.2 Keyword Argument 118
8.2.3 Default Value 118
8.2.4 equivalent function call 119
8.2.5 Avoid argument errors 120
8.3 Return value 121
8.3.1 Return simple Value 121
8.3.2 make the argument an optional 122
8.3.3 Back to Dictionary 123
8.3.4 with functions and while loops 124
8.4 Delivery List 126
8.4.1 Modifying a list in a function 126
8.4.2 Prohibit function modification list 129
8.5 Pass any number of arguments 130
8.5.1 using positional arguments together with any number of arguments 131
8.5.2 use any number of keyword arguments 131
8.6 Storing a function in a module 133
8.6.1 importing the entire module 133
8.6.2 importing a specific function 134
8.6.3 using as to assign aliases to functions 134
8.6.4 Assigning an alias to a module using as 135
8.6.5 all functions in the Import module 135
8.7 Guide to writing a function 136
8.8 Summary 137
Chapter 9th Class 138
9.1 Creating and using classes 138
9.1.1 Creating a Dog class 139
9.1.2 creating an instance based on a class 140
9.2 Using classes and instances 142
9.2.1 Car Class 143
9.2.2 Assigning a default value of 143 to a property
9.2.3 Modifying the value of a property 144
9.3 Inheritance 147
Methods of 9.3.1 Subclasses __init__ () 147
9.3.2 inheritance in Python 2.7 149
9.3.3 defining properties and methods for subclasses 149
9.3.4 overriding the parent class method 150
9.3.5 using an instance as an attribute 150
9.3.6 Simulating physical 152
9.4 Importing Classes 153
9.4.1 Importing a single class 153
9.4.2 storing multiple classes in a module 155
9.4.3 importing multiple classes from a module 156
9.4.4 importing the entire module 157
9.4.5 all classes in the Import module 157
9.4.6 importing another module in one module 157
9.4.7 Customizing Workflow 158
9.5 Python Standard library 159
Class 9.6 Coding style 161
9.7 Summary 161
10th. Files and Exceptions 162
10.1 reading data from a file 162
10.1.1 reading the entire file 162
10.1.2 File Path 164
10.1.3 Read-line 165
10.1.4 Create a list containing the contents of each line of the file 166
10.1.5 using the contents of a file 166
10.1.6 contains 1 million-bit large files 168
10.1.7 pi values include your birthday? 168
10.2 Writing to a file 169
10.2.1 Writing empty file 170
10.2.2 Write multiple lines 170
10.2.3 Attaching to File 171
10.3 Exception 172
10.3.1 Handling Zerodivisionerror Exceptions 172
10.3.2 using try-except code block 173
10.3.3 using exceptions to avoid crashes 173
10.3.4 Else code block 174
10.3.5 Handling Filenotfounderror Exceptions 175
10.3.6 parsing text 176
10.3.7 Using multiple Files 177
10.3.8 fails without a sound 178
10.3.9 decide which errors to report 179
10.4 Storing Data 180
10.4.1 using Json.dump () and json.load () 180
10.4.2 Saving and reading user-generated data 181
10.4.3 Refactoring 183
10.5 Summary 186
11th Test Code 187
11.1 Test Function 187
11.1.1 unit tests and test cases 188
11.1.2 Available tests 188
11.1.3 cannot pass the test 190
What to do when 11.1.4 tests are not passed 191
11.1.5 Adding a new test 191
11.2 Test Class 193
11.2.1 Various assertion Methods 193
11.2.21 Classes to test 194
11.2.3 Test Anonymoussurvey Class 195
11.2.4 Method Setup () 197
11.3 Summary 199
Part II Project
Item 1 Alien Invasion 202
12th Armed spacecraft 203
12.1 Planning Project 203
12.2 Installing Pygame 204
12.2.1 installing Python packages with PIP 204
12.2.2 installing Pygame 206 on Linux Systems
12.2.3 installing Pygame 207 in OS X systems
12.2.4 installing Pygame 207 in a Windows system
12.3 Starting Game Item 207
12.3.1 Create Pygame window and respond to user input 208
12.3.2 Setting the background color 209
12.3.3 Creating a Settings Class 210
12.4 Adding a spaceship image 211
12.4.1 creating a ship class 212
12.4.2 painting the spaceship on the screen 213
12.5 Refactoring: module Game_functions 214
12.5.1 function check_events () 214
12.5.2 function Update_screen () 215
12.6 driving the Spaceship 216
12.6.1 Response Button 216
12.6.2 allows for constant movement of 217
12.6.3 move around 219
12.6.4 Adjust the speed of the ship 220
12.6.5 limit the scope of the ship's activities 221
12.6.6 refactoring check_events () 222
12.7 Simple Review 223
12.7.1 alien_invasion.py 223
12.7.2 settings.py 223
12.7.3 game_functions.py 223
12.7.4 ship.py 223
12.8 shooting 224
12.8.1 Add Bullet Set 224
12.8.2 Creating Bullet Class 224
12.8.3 storing bullets in a group 226
12.8.4 Fire 227
12.8.5 remove a missing bullet 228
12.8.6 Limit number of bullets 229
12.8.7 Creating a function update_bullets () 229
12.8.8 Creating a function Fire_bullet () 230
12.9 Summary 231
13th Alien 232
13.1 Review Item 232
13.2 creation of the first alien 233
13.2.1 creating Alien Class 233
13.2.2 Creating a Alien instance 234
13.2.3 let aliens appear on the screen 235
13.3 Creating a group of aliens 236
13.3.1 determine how many aliens a row can hold 236
13.3.2 creating multiple lines of aliens 236
13.3.3 Create alien Crowd 237
13.3.4 refactoring Create_fleet () 239
13.3.5 Adding rows 240
13.4 Let the alien crowd move 242
13.4.1 to the right to move aliens 243
13.4.2 creating a setting that represents the direction of alien movement 244
13.4.3 Check if aliens hit the edge of the screen. 244
13.4.4 move the alien swarm down and change the direction of movement 245
13.5 Shooting Aliens 246
13.5.1 detects a bullet collision with an alien 246
13.5.2 creating a large bullet for testing 247
13.5.3 generation of new alien population 248
13.5.4 increase the speed of the bullet by 249
13.5.5 refactoring Update_bullets () 249
13.6 End Game 250
13.6.1 detects aliens and spacecraft collisions 250
13.6.2 responds to aliens and spacecraft collisions 251
13.6.3 has aliens reaching the bottom of the screen 254
13.6.4 Game Over 255
13.7 Determine which parts of the game should be run 255
13.8 Summary 256
14th Chapter 257
14.1 Adding the play button 257
14.1.1 Creating a Button class 258
14.1.2 Draw a button on the screen 259
14.1.3 Start Game 261
14.1.4 Resetting the game 261
14.1.5 to switch the play button to inactive 263
14.1.6 Hide Cursor 263
14.2 Increase Level 264
14.2.1 Modifying the Speed setting 264
14.2.2 Reset Speed 266
14.3 Scoring 267
14.3.1 Show Score 267
14.3.2 Creating a scoreboard 268
14.3.3 Update score 270 When aliens are wiped out.
14.3.4 will destroy every alien's points count to score 271
14.3.5 Increase points 271
14.3.6 will score round 272
14.3.7 Maximum score 274
14.3.8 Display Level 276
14.3.9 shows the remaining number of ships 279
14.4 Summary 283
Item 2 Visualization of data 284
15th. Generating Data 285
15.1 Installing Matplotlib 285
15.1.1 installing Matplotlib 286 on Linux Systems
15.1.2 installing Matplotlib 286 in OS X systems
15.1.3 installing Matplotlib 286 in a Windows system
15.1.4 Test Matplotlib 287
15.1.5 Matplotlib Gallery 287
15.2 Draw a simple line chart 287
15.2.1 modifying label text and line weights 288
15.2.2 Correcting Graphics 289
15.2.3 using scatter () to draw a scatter plot and set its style 290
15.2.4 using scatter () to draw a series of points 291
15.2.5 automatic calculation of data 292
15.2.6 removing the contour of a data point 293
15.2.7 Custom Colors 293
15.2.8 Using color maps 294
15.2.9 Auto Save Diagram 295
15.3 Random Walk 295
15.3.1 Creating Randomwalk () class 296
15.3.2 Select Direction 296
15.3.3 drawing a random walk figure 297
15.3.4 simulation multiple random walk 298
15.3.5 setting the style of a random walk chart 299
15.3.6 Coloring Point 299
15.3.7 redraw start and end 300
15.3.8 Hide Axis 301
15.3.9 Add points 301
15.3.10 resizing to fit on screen 302
15.4 using Pygal to simulate the dice 303
15.4.1 Mounting Pygal 304
15.4.2 Pygal Gallery 304
15.4.3 creating Die Class 304
15.4.4 Roll the Dice 305
15.4.5 Analysis Results 305
15.4.6 drawing a Histogram 306
15.4.7 throw two dice at a time 307
15.4.8 two dice with different number of faces at the same time 309
15.5 Summary 311
16th Chapter Download Data 312
16.1 CSV file Format 312
16.1.1 parsing csv file header 313
16.1.2 Print the file header and its location 314
16.1.3 extracting and reading data 314
16.1.4 drawing the temperature chart 315
16.1.5 module datetime 316
16.1.6 Adding a date 317 to a chart
16.1.7 covers a longer period of time 318
16.1.8 Draw a data series 319
16.1.9 to color the chart area 320
16.1.10 Error Checking 321
16.2 Making World Population map: JSON format 324
16.2.1 Download World Population Data 324
16.2.2 Extract related Data 324
16.2.3 converting a string to a numeric value 326
16.2.4 get a two-letter country code 327
16.2.5 making the world map 329
16.2.6 digital data on the world map 330
16.2.7 Drawing the complete World population map 331
16.2.8 country groupings 333 according to population size
16.2.9 using Pygal to set the style of the world map 334
16.2.10 Highlight Color Theme 335
16.3 Summary 337
Chapter 17th using API 338
17.1 using the Web API 338
17.1.1 git and GitHub 338
17.1.2 using API calls to request data 339
17.1.3 Mounting Requests 339
17.1.4 Processing API Response 340
17.1.5 Processing Response Dictionary 340
17.1.6 Overview The most popular warehouses 342
17.1.7 Monitoring API Rate Limit 343
17.2 using the Pygal visualization warehouse 344
17.2.1 Improved Pygal chart 346
17.2.2 Adding a custom ToolTip 347
17.2.3 drawing based on data 349
17.2.4 Adding a click link to a chart 350
17.3 Hacker News API 350
17.4 Summary 353
Project 3 WEB Application 354
18th Django Introduction 355
18.1 Building a Project 355
18.1.1 Development of Specifications 355
18.1.2 setting up a virtual environment 356
18.1.3 Mounting Virtualenv 356
18.1.4 activating a virtual environment 357
18.1.5 Installing Django 357
18.1.6 creating a project in Django 357
18.1.7 Creating a Database 358
18.1.8 View Item 359
18.2 Creating an Application 360
18.2.1 Defining a Model 360
18.2.2 Activating the Model 362
18.2.3 Django Administration Site 363
18.2.4 Defining a Model entry 365
18.2.5 Migration Model Entry 366
18.2.6 registering with the Administration Website entry 366
18.2.7 Django Shell 367
18.3 Creating a Web page: Learning Notes Home 369
18.3.1 Mapping URL 369
18.3.2 writing a view 371
18.3.3 writing a template 372
18.4 Creating additional pages 373
18.4.1 Template Inheritance 373
18.4.2 displaying all topics on page 375
18.4.3 displaying page 378 for a specific topic
18.5 Summary 381
19th Chapter User Account 382
19.1 enabling users to enter data 382
19.1.1 adding a new theme 382
19.1.2 Adding a new entry 386
19.1.3 Edit Entry 390
19.2 Creating a user account 392
19.2.1 Applications Users 393
19.2.2 Login Page 394
19.2.3 Logoff 396
19.2.4 Registration Page 397
19.3 let users have their own data 400
19.3.1 restricting access using @login_required 400
19.3.2 associating data to users 402
19.3.3 only allows users to access their own theme 405
19.3.4 protecting a user's theme 405
19.3.5 Protection page Edit_entry 406
19.3.6 associating a new theme to the current user 406
19.4 Summary 408
20th. Set the style of the application and deploy it 409
20.1 Setting the style of the project "Learning note" 409
20.1.1 Application DJANGO-BOOTSTRAP3 410
20.1.2 using bootstrap to set the style of the project "Learning note" 411
20.1.3 modifying base.html 411
20.1.4 Styling the home page using Jumbotron 414
20.1.5 Setting the login page style 415
20.1.6 setting the style of the New_topic page 416
20.1.7 setting the style of the topics page 417
20.1.8 setting the style of entries in the topic page 417
20.2 deployment of "study notes" 419
20.2.1 establishing Heroku Account 420
20.2.2 mounting Heroku Toolbelt 420
20.2.3 installing the necessary packages 420
20.2.4 creating a file containing a list of packages Requirements.txt 421
20.2.5 Specifying Python version 422
20.2.6 modifying settings.py for deployment to Herohu 422
20.2.7 creating Procfile 423 of the boot process
20.2.8 modifying wsgi.py for deployment to Herohu 423
20.2.9 creating a directory to store static files 424
20.2.10 using Gunicorn server 424 locally
20.2.11 using Git to track project files 425
20.2.12 push to Heroku 426
20.2.13 building a database on Heroku 427
20.2.14 Improving Heroku Deployment 428
20.2.15 ensuring the safety of the project 429
20.2.16 Submit and push changes 430
20.2.17 Creating a custom error page 431
20.2.18 continues to develop 434
20.2.19 Setting Secret_key 434
20.2.20 Deleting a project from Heroku 434
20.3 Summary 435
Appendix A, installing Python 436
Appendix B Text Editor 441
Appendix C seeking Help 447
Appendix D using Git for version control 451
PostScript 460

"Python programming: from getting started to practicing" [Eric Matthes] Chinese PDF non-scanned version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.