Python Crash Course 原版PDF by Matthes

所需积分/C币:50 2018-05-05 09:38:10 5.23MB PDF
收藏 收藏

Every programmer has a story about how they learned to write their first program. I started learning as a child when my father was working for Digital Equipment Corporation, one of the pioneering companies of the modern computing era. I wrote my first program on a kit computer my dad had assembled in our basement. The computer consisted of nothing more than a bare motherboard connected to a keyboard without a case, and it had a bare cathode ray tube for a monitor. My initial program was a simple number guessing game, which looked something like this
PYTHON CRASH COURSE. Copyright o 2016 by Eric Matthes Il rights reserved. No part of this work may be reproduced or transmitted in any form or by any means electronic or mechanical, including photocopying, recording, or by any information storag ge or retrieval system, without the prior written permission of the copyright owner and the publisher First printing 1918171615123456789 ISBN-10:1-59327-603-6 ISBN-13:978-1-59327-603-4 Publisher: william pollock Production editor: riley hoffman Cover Illustration: Josh Ellingson Interior Design: Octopod Studios Developmental Editors: William Pollock, Liz Chadwick, and Leslie Shen Technical reviewer: Kenneth love Copyeditor: Anne Marie Walker Compositor: Riley Hoffman Proofreader: James Fraleigh For information on distribution, translations, or bulk sales, please contact No Starch Press, InC. directly No Starch Press Inc 245 8th Street. San Francisco. CA 94103 phone415.863.9900; Library of Congress Cataloging-in-Publication data Matthes, Eric, 19 Python crash course a hands-on, project-based introduction to programming by Eric Matthes pages cm Includes index Summary: A project-based introduction to programming in Python, with exercises. Covers general programming concepts, Python fundamentals, and problem solving. Includes three projects how to create a simple video game, use data visualization techniques to make graphs and charts, and build an interactive web application"-- Provided by publisher ISBN978-1-59327-603-4--ISBN1-59327-603-6 mputer program language) I. Title QA76.73.P98M382015 005.13'3--dc23 015018135 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The information in this book is distributed on an"As Is"basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. BRIEF CONTENTS Acknowledgments ......,XXV Introduction ,,,..,.XXX part BASICS。,,,,。,。。。。。,。,。,,。。。。,。。,。。。,,,。。。, Chapter 1: Getting Started Chapter 2 Variables and Simple data Types 19 Chapter 3: Introducing Lists 37 Chapter 4: Working with Lists 53 Chapter 5: if Statements Chapter 6: Dictionaries 95 Chapter 7: User Input and while Loops 117 Chapter 8: Functions 133 Chapter 9: Classes ....161 Chapter 10: Files and Exceptions ....189 Chapter 11: Testing Your Code 215 PART B PROJECTS,。,,,,,,。。,,,,。。,。。。,,。,,,,,23 Project 1: Alien Invasion Chapter 12: A Ship that Fires bullets ....235 Chapter 13: Aliens 265 Chapter 14: Scoring 291 Project 2 Data Visualization Chapter 15: Generating Data 321 Chapter 16: Downloading Data 349 Chapter 17: Working with APls 377 Project 3: Web Applications Chapter 18: Getting Started with Diange 397 Chapter 19: User Accounts 427 Chapter 20: Styling and Deploying an App 455 Afte 483 Appendix A: Installing Python 485 Appendix B: Text Editors 491 Appendix C: Getting Help .499 Appendix D: Using Git for Version Control .505 Index 515 CONTENTS IN DETAIL ACKNOWLEDGMENTS XVI INTRODUCTION XXX Who ls this book fore What Can You Expect to Learne Why python? XXXI part basics GETTING STARTED Setting Up Your Programming Environment Python 2 and Python 3 4 Running Snippets of Python Code 4 Hello world 4 Python on Different○ perating Systems.∴ 5 Python on linux Python on OSⅩ ndows Troubleshooting Installation lssues Running python Programs from a terminal 16 n linux and○sX 16 On windows 16 Exercise 1-1 python. org Ex -2: Hello world typ 77 Exercise 1-3 Infinite skills 7 Summary ..17 VARIABLES AND SIMPLE DATA TYPES 19 appens nen you run hello wor 19 ariables 20 Naming and Using Variables 2 Avoiding Name Errors When Using Variables 2 Exercise 2-1 Simple Message 23 Exercise 2-2: Simple Messages 23 Strings 23 Changing case in a String with Methods 24 Combining or Concatenating Strings 25 Adding Whitespace to Strings with Tabs or Newlines 26 Stripping Whitespace 26 Avoiding Syntax Errors with Strings 28 Printing in Python 2 29 Exercise 2-3: Personal Message 29 Exercise 2-4: Name Cases 29 Exercise 2-5: Famous Quote 29 Exercise 2-6: Famous quote 2 29 Exercise 2-7: Stripping Names 9 umbers Integers Floats 0 Avoiding Type Errors with the str() Function 233333 Integers in Python 2 Exercise 2-8 Number Eight 33 Exercise 2-9 Favorite Number 33 Comments How Do You Write Comments 33 33 What Kind of comments should You write? 33 Exercise 2-10: Adding comments 34 The Zen of Python 34 Exercise 2-11: Zen of python 36 umma 36 INTRODUCING LISTS What Is a liste 37 Accessing elements in a List 38 Index positions start ato. not 1 39 Using Individual values from a list 39 Exercise 3-1: Names 40 E e3-2:G 40 Exercise 3-3: your Own lis 40 Changing, Adding and Removing Elements Modifying Elements in a List 40 Adding Elements to a List 4 Removing Elements from a List 42 Exercise 3-4: Guest list 46 Exercise 3-5: Changing Guest List 46 Exercise 3-6: More Guests 46 Exercise 3-7: Shrinking Guest List 47 Organizing a List 47 orting a List Permanently with the sort( Method ......47 Sorting a List Temporarily with the sorted Function 48 Printing a List in Reverse Order 49 Finding the length of a List 49 Exercise 3-8: Seeing the World 50 Exercise 3-9. Dinner guests 50 Exercise 3-10: Every Function 50 Avoiding Index Errors When Working with Lists 50 Exercise 3-11: Intentional error .....52 Summary 52 4 WORKING WITH LISTS 53 Looping Through an Entire List 53 A Closer Look at looping 54 Doing More Work Within a for Loop ..55 doing something after a for loop 56 XII Contents in deta Avoiding Indentation Errors 57 Forgetting to Indent 57 Forgetting to Indent Additional Lines 58 Indenting Unnecessarily 59 Indenting Unnecessarily After the Loop 59 Forgetting the Colon 60 Exercise 4-1: Pizzas 0 Exercise 4-2. Animals 60 Making numerical lists 61 sing the range( Function 61 Using range() to make a List of Numbers ......62 Simple statistics with a list of Numbers 63 List Comprehensions Exercise 4-3: Counting to Twenty Exercise 4-4: One Million 64 Exercise 4-5: Summing a Million 64 Exercise 4-6 Odd Numbers 64 Exercise 4-7. threes 64 Exercise 4-8 cubes Exercise 4-9: Cube Comprehension 64 orking with part of a list 65 Slicing a List ......65 Looping Through a Slice 66 Copying a list 67 Exercise 4-10: Slices 9 Exercise 4-71: My Pizzas, Your Pizzas 69 Exercise 4-72: More Loops ..69 Tuples 69 Defining a tuple ..69 coping through all values in a tuple 70 riting over a tuple 71 Exercise4-13:Bu所et Styling your code The Style Guide Indentation le Length 73 Blank li 73 Other Style Guidelines Exercise 4-14: Pep 8 Exercise 4-15: Code Review ..4 mary 74 IF STATEMENTS 75 A Simple Example Conditional tests 76 ekin 76 Ignoring Case When Checking for Equality Checking for Inequality 78 Numerical Comparisons 78 Checking Multiple Conditions 79 Checking whether a value ls in a List 80 Contents in Detai Checking Whether a value ls not in a List 81 Boolean Expressions 81 Exercise 5-1 Conditional Tests 82 Exercise 5-2. More Conditional tests 82 「 Statements 82 Simple if Statements 82 if-else statements 83 The if-elif-else Chain 84 Using multiple elif blocks 86 Omitting the else block 86 Testing Multiple Conditions 87 Exercise 5-3 Alien colors #1 88 Exercise 5-4: Alien colors #2 88 Exercise 5-5 Alien Colors #3 89 Exercise 5-6: Stages of life 89 Exercise 5-7. Favorite Fruit 89 Using if Statements with Lists ......89 Checking for Special Items 90 Checking That a List Is Not Empty 91 Using multiple lists 92 Exercise 5-8 Hello admin 93 Exercise 5-9. No Users 93 Exercise 5-10: Checking Usernames 93 Exercise 5-11 Ordinal numbers 93 Styling Your if Statements 94 Exercise 5-12 Styling if statements Exercise 5-13 Your Ideas Summary 444 9 DICTIONARIES 95 A Simple Dictionary 96 Working with Dictionaries 96 Accessing Values in a Dictionary 97 Adding New Key-Value Pairs 97 Starting with an Empty Dictionary 98 Modifying Values in a Dictionary 99 Removing Key-value Pairs 100 A Dictionary of Similar Objects 100 Exercise 6-1: Person 702 Exercise 6-2. Favorite Numbers 702 Exercise 6-3: Glossary 702 Looping Through a Dictionary 102 Looping through all Key-Value Pairs 103 coping Through All the Keys in a Dictionary 104 coping Through a Dictionary's Keys in Order 106 Looping hrough All Values in a Dictionary. 107 Exercise 6-4: Glossary 2 08 Exercise 6-5: Rivers 708 Exercise 6-6: Polling 708 g 109 A List of dictionaryⅰes .109 A list in a dicti A Dictionary in a Dictionary Exercise 6-7: People 714 Exercise 6-8: Pets 715 Exercise 6-9. Favorite places 775 Exercise 610 Favorite Numbers 775 E 6-11: Citi 775 Exercise 6-12. Extensions 775 ummary 115 USER INPUT AND WHILE LOOPS 117 How the input() Function Works 118 ng Clear Prompts 118 Using int() to Accept Numerical Input The Modulo Operator 120 Accepting Input in Python 2.7 12 Exercise 7-1: Rental car 27 Exercise 7-2: Restaurant Seating 127 Exercise 7-3: Multiples of Ten 12 Introducing while Loops .......122 The while Loop in Action 122 Letting the User Choose When to Quit 122 Using a flag 124 Using break to Exit a Loop ...125 Using continue in a Loop 126 Avoiding Infinite Loops 126 Exercise 7-4 Pizza Toppings 127 Exercise 7-5: movie tickets 127 Exercise 7-6 Three exits 28 Exercise 7-7: Infinity 128 Using a while Loop with lists and Dictionaries 28 Moving Items from One List to Another .128 Removing all Instances of specific Values from a List 129 Filling a Dictionary with User Input 130 Exercise 7-8: Deli 137 Exercise 7-9. No pastrami 137 Exercise 7-10: Dream Vacatic 73 131 FUNCTIONS 133 Defining a Function 134 Passing information to a function 134 Arguments and Parameters 135 Exercise 8-1 Message 135 Exercise 8-2. Favorite Book 135 Passing Arguments 135 Positional arguments 136 d arguments 137 Default∨aues 138 s in detail xv

试读 127P Python Crash Course  原版PDF by  Matthes
立即下载 低至0.43元/次 身份认证VIP会员低至7折
Oren_HG 书是不错的,浅显易懂,不过有点太基础了,看起来太慢了,不如网上看个教程快速入门
acskevin 英文原版确认
Python Crash Course 原版PDF by Matthes 50积分/C币 立即下载
Python Crash Course  原版PDF by  Matthes第1页
Python Crash Course  原版PDF by  Matthes第2页
Python Crash Course  原版PDF by  Matthes第3页
Python Crash Course  原版PDF by  Matthes第4页
Python Crash Course  原版PDF by  Matthes第5页
Python Crash Course  原版PDF by  Matthes第6页
Python Crash Course  原版PDF by  Matthes第7页
Python Crash Course  原版PDF by  Matthes第8页
Python Crash Course  原版PDF by  Matthes第9页
Python Crash Course  原版PDF by  Matthes第10页
Python Crash Course  原版PDF by  Matthes第11页
Python Crash Course  原版PDF by  Matthes第12页
Python Crash Course  原版PDF by  Matthes第13页
Python Crash Course  原版PDF by  Matthes第14页
Python Crash Course  原版PDF by  Matthes第15页
Python Crash Course  原版PDF by  Matthes第16页
Python Crash Course  原版PDF by  Matthes第17页
Python Crash Course  原版PDF by  Matthes第18页
Python Crash Course  原版PDF by  Matthes第19页
Python Crash Course  原版PDF by  Matthes第20页

试读结束, 可继续阅读

50积分/C币 立即下载 >