没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Crash Course 3rd Edition-2022-英文版.pdf
Python Crash Course 3rd Edition-2022-英文版-赞誉4.
需积分: 5 48 下载量 92 浏览量
更新于2023-11-23
评论
收藏 7.97MB PDF 举报
《Python Crash Course 3rd Edition-2022-英文版.pdf》是一本深受赞誉的Python编程入门教材。根据评论者的评价,这本书以一种一贯、逻辑和愉快的方式,分阶段地引导读者构建更复杂的代码,并对代码片段进行了良好的解释。读者评论中提到,使用《Python Crash Course》学习Python是一种非常积极的体验。这本书不仅涵盖了Python编程的基础知识,还涉及了一些复杂项目。同时,评论者认为这本书的写作风格很吸引人,能够吸引读者深入学习这一主题。总的来说,《Python Crash Course 3rd Edition-2022-英文版.pdf》是一本与传统编程书籍并列的未来经典之作,深受广大读者的喜爱和推崇。无疑,这本书是Python初学者的不二之选。
资源详情
资源评论
资源推荐
xivContents in Detail
Other Style Guidelines........................................ 69
Exercise 4-14: PEP 8 ........................................ 70
Exercise 4-15: Code Review ................................... 70
Summary ....................................................... 70
5
IF STATEMENTS 71
A Simple Example ................................................. 72
Conditional Tests .................................................. 72
Checking for Equality ........................................ 72
Ignoring Case When Checking for Equality ......................... 73
Checking for Inequality ....................................... 74
Numerical Comparisons ...................................... 74
Checking Multiple Conditions ................................... 75
Checking Whether a Value Is in a List ............................. 76
Checking Whether a Value Is Not in a List . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Boolean Expressions ......................................... 77
Exercise 5-1: Conditional Tests ................................. 77
Exercise 5-2: More Conditional Tests ............................. 78
if Statements ..................................................... 78
Simple if Statements ......................................... 78
if-else Statements............................................ 79
The if-elif-else Chain ......................................... 80
Using Multiple elif Blocks ...................................... 81
Omitting the else Block ....................................... 82
Testing Multiple Conditions..................................... 82
Exercise 5-3: Alien Colors #1 .................................. 84
Exercise 5-4: Alien Colors #2 .................................. 84
Exercise 5-5: Alien Colors #3 .................................. 84
Exercise 5-6: Stages of Life .................................... 84
Exercise 5-7: Favorite Fruit .................................... 85
Using if Statements with Lists .......................................... 85
Checking for Special Items ..................................... 85
Checking That a List Is Not Empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Using Multiple Lists .......................................... 87
Exercise 5-8: Hello Admin .................................... 88
Exercise 5-9: No Users ...................................... 88
Exercise 5-10: Checking Usernames ............................. 88
Exercise 5-11: Ordinal Numbers ................................ 88
Styling Your if Statements ............................................ 89
Exercise 5-12: Styling if Statements .............................. 89
Exercise 5-13: Your Ideas ..................................... 89
Summary ....................................................... 89
6
DICTIONARIES 91
A Simple Dictionary ................................................ 92
Working with Dictionaries ............................................ 92
Accessing Values in a Dictionary................................. 92
Adding New Key-Value Pairs ................................... 93
Starting with an Empty Dictionary ................................ 94
Contents in Detailxv
Modifying Values in a Dictionary ................................ 94
Removing Key-Value Pairs ..................................... 96
A Dictionary of Similar Objects.................................. 96
Using get() to Access Values .................................... 97
Exercise 6-1: Person ........................................ 98
Exercise 6-2: Favorite Numbers ................................ 98
Exercise 6-3: Glossary ....................................... 99
Looping Through a Dictionary ......................................... 99
Looping Through All Key-Value Pairs .............................. 99
Looping Through All the Keys in a Dictionary . . . . . . . . . . . . . . . . . . . . . . . 101
Looping Through a Dictionary’s Keys in a Particular Order.............. 102
Looping Through All Values in a Dictionary ........................ 103
Exercise 6-4: Glossary 2 .................................... 104
Exercise 6-5: Rivers ........................................ 105
Exercise 6-6: Polling ....................................... 105
Nesting........................................................ 105
A List of Dictionaries ........................................ 105
A List in a Dictionary ........................................ 108
A Dictionary in a Dictionary................................... 110
Exercise 6-7: People ....................................... 111
Exercise 6-8: Pets ......................................... 111
Exercise 6-9: Favorite Places ................................. 111
Exercise 6-10: Favorite Numbers .............................. 111
Exercise 6-11: Cities ....................................... 111
Exercise 6-12: Extensions .................................... 111
Summary ...................................................... 111
7
USER INPUT AND WHILE LOOPS 113
How the input() Function Works ....................................... 114
Writing Clear Prompts ....................................... 114
Using int() to Accept Numerical Input............................. 115
The Modulo Operator ....................................... 116
Exercise 7-1: Rental Car ..................................... 117
Exercise 7-2: Restaurant Seating ............................... 117
Exercise 7-3: Multiples of Ten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Introducing while Loops ............................................ 117
The while Loop in Action ..................................... 117
Letting the User Choose When to Quit ............................ 118
Using a Flag.............................................. 120
Using break to Exit a Loop .................................... 121
Using continue in a Loop ..................................... 122
Avoiding Infinite Loops....................................... 122
Exercise 7-4: Pizza Toppings ................................123
Exercise 7-5: Movie Tickets .................................. 123
Exercise 7-6: Three Exits .................................... 123
Exercise 7-7: Infinity ....................................... 123
Using a while Loop with Lists and Dictionaries ............................. 124
Moving Items from One List to Another............................ 124
Removing All Instances of Specific Values from a List .................. 125
Filling a Dictionary with User Input .............................. 125
Exercise 7-8: Deli ......................................... 127
xviContents in Detail
Exercise 7-9: No Pastrami ................................... 127
Exercise 7-10: Dream Vacation ................................ 127
Summary ...................................................... 127
8
FUNCTIONS 129
Defining a Function ............................................... 130
Passing Information to a Function ............................... 130
Arguments and Parameters.................................... 131
Exercise 8-1: Message ...................................... 131
Exercise 8-2: Favorite Book .................................. 131
Passing Arguments ................................................ 131
Positional Arguments ........................................ 132
Keyword Arguments ........................................ 133
Default Values............................................. 134
Equivalent Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Avoiding Argument Errors .................................... 136
Exercise 8-3: T-Shirt ........................................ 136
Exercise 8-4: Large Shirts .................................... 137
Exercise 8-5: Cities ........................................ 137
Return Values.................................................... 137
Returning a Simple Value ..................................... 137
Making an Argument Optional ................................. 138
Returning a Dictionary ....................................... 139
Using a Function with a while Loop .............................. 140
Exercise 8-6: City Names .................................... 141
Exercise 8-7: Album ....................................... 142
Exercise 8-8: User Albums ................................... 142
Passing a List.................................................... 142
Modifying a List in a Function .................................. 143
Preventing a Function from Modifying a List ........................ 145
Exercise 8-9: Messages ..................................... 146
Exercise 8-10: Sending Messages .............................. 146
Exercise 8-11: Archived Messages ............................. 146
Passing an Arbitrary Number of Arguments............................... 146
Mixing Positional and Arbitrary Arguments ........................ 147
Using Arbitrary Keyword Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Exercise 8-12: Sandwiches ................................... 149
Exercise 8-13: User Profile ................................... 149
Exercise 8-14: Cars ........................................ 149
Storing Your Functions in Modules ..................................... 149
Importing an Entire Module ................................... 150
Importing Specific Functions ................................... 151
Using as to Give a Function an Alias............................. 151
Using as to Give a Module an Alias ............................. 152
Importing All Functions in a Module ............................. 152
Styling Functions ................................................. 153
Exercise 8-15: Printing Models ................................ 154
Exercise 8-16: Imports ...................................... 154
Exercise 8-17: Styling Functions ............................... 154
Summary ...................................................... 154
Contents in Detailxvii
9
CLASSES 157
Creating and Using a Class.......................................... 158
Creating the Dog Class ...................................... 158
The __init__() Method ....................................... 159
Making an Instance from a Class ............................... 159
Exercise 9-1: Restaurant ..................................... 162
Exercise 9-2: Three Restaurants ................................ 162
Exercise 9-3: Users ........................................ 162
Working with Classes and Instances.................................... 162
The Car Class............................................. 162
Setting a Default Value for an Attribute ........................... 163
Modifying Attribute Values .................................... 164
Exercise 9-4: Number Served ................................. 166
Exercise 9-5: Login Attempts ....................................167
Inheritance ..................................................... 167
The __init__() Method for a Child Class ........................... 167
Defining Attributes and Methods for the Child Class .................. 169
Overriding Methods from the Parent Class ......................... 170
Instances as Attributes ....................................... 170
Modeling Real-World Objects.................................. 172
Exercise 9-6: Ice Cream Stand ................................ 173
Exercise 9-7: Admin ....................................... 173
Exercise 9-8: Privileges ..................................... 173
Exercise 9-9: Battery Upgrade ................................ 173
Importing Classes................................................. 173
Importing a Single Class ..................................... 174
Storing Multiple Classes in a Module............................. 175
Importing Multiple Classes from a Module ......................... 176
Importing an Entire Module ................................... 176
Importing All Classes from a Module ............................. 177
Importing a Module into a Module .............................. 177
Using Aliases ............................................. 178
Finding Your Own Workflow .................................. 179
Exercise 9-10: Imported Restaurant ............................. 179
Exercise 9-11: Imported Admin ................................ 179
Exercise 9-12: Multiple Modules ............................... 179
The Python Standard Library ......................................... 179
Exercise 9-13: Dice ........................................ 180
Exercise 9-14: Lottery ...................................... 180
Exercise 9-15: Lottery Analysis ................................ 180
Exercise 9-16: Python Module of the Week ....................... 180
Styling Classes................................................... 181
Summary ...................................................... 181
10
FILES AND EXCEPTIONS 183
Reading from a File ............................................... 184
Reading the Contents of a File ................................. 184
Relative and Absolute File Paths ................................ 186
Accessing a File’s Lines ...................................... 186
xviiiContents in Detail
Working with a File’s Contents ................................. 187
Large Files: One Million Digits ................................. 188
Is Your Birthday Contained in Pi? ............................... 189
Exercise 10-1: Learning Python ................................ 189
Exercise 10-2: Learning C ................................... 190
Exercise 10-3: Simpler Code ................................. 190
Writing to a File.................................................. 190
Writing a Single Line ........................................ 190
Writing Multiple Lines ....................................... 191
Exercise 10-4: Guest ....................................... 192
Exercise 10-5: Guest Book ......................................192
Exceptions...................................................... 192
Handling the ZeroDivisionError Exception ......................... 192
Using try-except Blocks ...................................... 193
Using Exceptions to Prevent Crashes ............................. 193
The else Block............................................. 194
Handling the FileNotFoundError Exception ......................... 195
Analyzing Text ............................................ 196
Working with Multiple Files ................................... 197
Failing Silently ............................................ 198
Deciding Which Errors to Report................................ 199
Exercise 10-6: Addition ..................................... 200
Exercise 10-7: Addition Calculator ............................. 200
Exercise 10-8: Cats and Dogs ................................ 200
Exercise 10-9: Silent Cats and Dogs ............................ 200
Exercise 10-10: Common Words .............................. 200
Storing Data .................................................... 201
Using json.dumps() and json.loads() ............................. 201
Saving and Reading User-Generated Data ......................... 202
Refactoring............................................... 204
Exercise 10-11: Favorite Number .............................. 206
Exercise 10-12: Favorite Number Remembered .................... 206
Exercise 10-13: User Dictionary ............................... 206
Exercise 10-14: Verify User .................................. 206
Summary ...................................................... 207
11
TESTING YOUR CODE 209
Installing pytest with pip ............................................ 210
Updating pip ............................................. 210
Installing pytest ............................................ 211
Testing a Function................................................. 211
Unit Tests and Test Cases ..................................... 212
A Passing Test............................................. 212
Running a Test ............................................ 213
A Failing Test ............................................. 214
Responding to a Failed Test ................................... 215
Adding New Tests.......................................... 216
Exercise 11-1: City, Country .................................. 217
Exercise 11-2: Population .......................................217
剩余553页未读,继续阅读
傻啦嘿哟
- 粉丝: 3478
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0