Introduction to Computer Programming with Python / Введение в компьютерное программирование на Python
Год издания: 2023
Автор: Wang Harris / Ван Харрис
Издательство: Remix
ISBN: 978-1-9989-4408-8
Язык: Английский
Формат: PDF, EPUB
Качество: Издательский макет или текст (eBook)
Количество страниц: 501
Описание: This introduction to computer programming with Python begins with some of the basics of computing and programming before diving into the fundamental elements and building blocks of computer programs in Python language. From the installation of Python, Python interactive programming, and integrated development environments to raising and handling exceptions, using compound data types to solve problems, and implement divide-and-conquer processes using functions, classes and modules, this textbook will set students up for success in programming and computing study and practice. The included exercises and projects are designed to hone students’ skills.
Это введение в компьютерное программирование на Python начинается с некоторых основ вычислительной техники и программирования, прежде чем погрузиться в фундаментальные элементы и строительные блоки компьютерных программ на языке Python. От установки Python, интерактивного программирования на Python и интегрированных сред разработки до создания и обработки исключений, использования составных типов данных для решения проблем и реализации процессов "разделяй и властвуй" с использованием функций, классов и модулей - этот учебник подготовит студентов к успеху в изучении и практике программирования и вычислительной техники. Включенные упражнения и проекты предназначены для оттачивания навыков учащихся.
Оглавление
Chapter 1 Introduction 1
Learning Objectives 1
1.1 A Brief History of Computers 1
1.2 Fundamentals of Computing and Modern Computers 5
Number Systems and the Foundation of Computing 6
Computability and Computational Complexity 9
The Construction of Modern Computers 11
Analog Computers 11
Digital Computers 12
Mechanic-Based Components 13
Vacuum Tube–Based Components 14
Transistors 14
Integrated Circuits and Very Large-Scale Integrated Circuits 14
1.3 Programming and Programming Languages 15
1.4 Python Programming Language 17
The Development and Implementation of Python 17
Advantages of Python 18
Resources for Python and Python Education 19
1.5 Getting Ready to Learn Programming in Python 20
Installing and Setting Up the Python Programming Environment 21
Installing Python 21
Setting Up a Virtual Environment for a Python Project 24
Installing Jupyter Notebook 26
Installing Visual Studio Code 27
Additional Tools Supporting Software Development in Python 27
Buildbot 27
Trac 28
Roundup 28
1.6 Getting a Taste of Programming with Python 28
Program Interactively with Python Interactive Shell 28
Program with VS Code IDE 30
Use Jupyter Notebook Within VS Code to Program Interactively 32
Write Documentation in Markdown 33
Headings 33
Paragraphs 34
New Lines 34
Italic, Bold, and Strikethrough Texts 34
Horizontal Rules 35
Keyboard Keys 35
Unordered Lists 35
Ordered Lists 36
Definition Lists 36
Links 37
Links to Internal Sections 37
Images 38
Blockquotes 38
Tables 39
Inline Program / Script Code 39
Code Block 40
Mathematical Formulas and Expressions 40
To-Do List 42
Escape Sequence for Special Characters 42
Programming Interactively with Jupyter Notebook Within VS Code 42
Run Python Programs Outside IDE 48
Make the Python Program File Executable 50
Errors in Programs 52
1.7 Essentials of Problem Solving and Software Development 54
Design Algorithms to Solve Problems 54
Phases of Software System Development 56
Phase 1. Understand the Project 57
Phase 2. Analyze the Requirements to Identify Computer-Solvable Problems and Tasks 57
Phase 3. Design the System 58
Phase 4. Implement the System 58
Phase 5. Test the System 58
Phase 6. Maintain the System 58
1.8 Manage Your Working Files for Software Development Projects 58
Set Up Git on Your Computer and Version-Control Locally 59
Set Up an Account on GitHub and Version-Control with Remote Repositories 62
Chapter Summary 67
Exercises 69
Projects 71
Chapter 2 Essential Building Blocks of Computer Programs 73
Learning Objectives 73
2.1 Primary Constructs of Computer Programs in Python 74
Vocabulary of the Programming Language 74
Rules of Naming Identifiers 76
Python Naming Conventions 79
Names with Leading and/or Trailing Underscores 79
Rules of Scope Resolution for Identifiers 81
Simple Data Types 82
Signed Integers (int) 83
Float (float) 87
Boolean (bool) 88
Complex (complex) 89
Compound Data Types 89
String (str) 90
List 95
Tuple 97
Set 98
Dictionary 99
Object 99
Variables and Constants 101
Variables 101
Built-In Constants 104
Operators 106
Arithmetic Operators 106
Comparison Operators 108
Logical Operators 109
Bitwise Operators 111
Assignment Operators 112
Identity Operators 115
Sequence Operators 115
Membership Operator 116
Built-In Functions 117
Expressions 135
2.2 Higher-Level Constructs of Python Programs 137
Structure of Python Programs 137
Documentation and Comments 139
Simple Statements 141
Expression Statement 141
Assignment Statement 143
print Statement 146
input Statement 149
assert Statement 150
pass Statement 151
del Statement 151
return Statement 152
open Statement 152
yield Statement 153
raise Statement 154
break Statement 155
continue Statement 155
import Statement 156
global Statement 156
nonlocal Statement 157
help Statement 158
Compound Statements 159
Code Blocks 159
Rules of Indentation 160
Rules of Spacing 160
if Statement 161
if-else Statement 162
if-elif Statement 163
if-elif-else Statement 165
while Statement 165
for Statement 166
def Statement 167
class Statement 168
try-except Statement 168
with Statement 169
Chapter Summary 170
Exercises 171
Projects 172
Chapter 3 Flow Control of Statements 175
Learning Objectives 175
3.1 Selective with the if Statement 175
3.2 Single-branch selective with if Statement 176
3.3 Multiple-Branch Selective with if-elif-… and if-elif-…-else Statements 177
3.4 Iterate with for Statement 180
Using break and continue Statements and an else Clause Within Loops 184
Common Coding Mistakes with the for Loop 185
3.5 Iterate with the while Statement 185
Common Coding Mistakes with a while Loop 190
3.6 Iterate with for Versus while 190
Chapter Summary 195
Exercises 195
Projects 196
Chapter 4 Handle Errors and Exceptions in
Programs 201
Learning Objectives 201
4.1 Errors in Your Programs 202
Exception 203
ArithmeticError 204
OverflowError 204
ZeroDivisionError 204
FloatingPointError 205
AssertionError 205
AttributeError 205
BufferError 206
EOFError 206
GeneratorExit 206
ImportError 206
IndexError 207
KeyError 207
KeyboardInterrupt 207
MemoryError 207
ModuleNotFoundError 207
NameError 208
NotImplementedError 208
OSError 208
BlockingIOError 208
ChildProcessError 208
ConnectionError 208
BrokenPipeError 209
ConnectionAbortedError 209
ConnectionRefusedError 209
ConnectionResetError 209
FileExistsError 209
FileNotFoundError 209
IsADirectoryError 209
NotADirectoryError 209
PermissionError 209
ProcessLookupError 210
TimeoutError 210
RecursionError 210
ReferenceError 210
RuntimeError 210
StopIteration 210
StopAsyncIteration 210
SyntaxError 210
IndentationError 211
TabError 211
SystemError 211
SystemExit 211
TypeError 211
UnboundLocalError 212
UnicodeError 212
UnicodeEncodeError 212
UnicodeDecodeError 212
UnicodeTranslateError 212
ValueError 212
4.2 Handling Runtime Errors and Exceptions 216
Chapter Summary 219
Exercises 220
Chapter 5 Use Sequences, Sets, Dictionaries, and
Text Files 221
Learning Objectives 221
5.1 Strings 222
Methods of Built-In
Class str 222
Built-In
Functions and Operators for Strings 232
Constructing and Formatting Strings 234
Regular Expressions 242
5.2 Lists 251
5.3 Tuples 258
5.4 Sets 261
5.5 Dictionaries 266
5.6 List, Set, and Dictionary Comprehension 271
List Comprehension 272
Set Comprehension 273
Dictionary Comprehension 274
5.7 Text Files 274
Opening and Closing a File 275
Write or Append to a File 278
Reading from a File 280
Update Existing Content of a Text File 284
Deleting Portion of a Text File 286
Chapter Summary 289
Exercises 291
Projects 292
Chapter 6 Define and Use Functions 295
Learning Objectives 295
6.1 Defining and Using Functions in Python 296
6.2 Parameters and Arguments in Functions 299
6.3 Recursive Functions 304
6.4 Anonymous Functions: lambda Expressions 308
6.5 Special Functions: Mapping, Filtering, and Reducing 310
Mapping 310
Filtering 311
Reducing 312
6.6 Generators: Turning a Function into a Generator of Iterables 312
6.7 Closures: Turning a Function into a Closure 316
6.8 Decorators: Using Function as a Decorator in Python 317
6.9 Properties of Functions 320
Chapter Summary 322
Exercises 322
Projects 323
Chapter 7 Object-Oriented
Programming with
Python 325
Learning Objectives 325
7.1 Introduction to Object-Oriented
Programming (OOP) 326
Abstraction 326
Information Hiding or Data Encapsulation 326
Inheritance 327
7.2 Defining and Using Classes in Python 327
Inheritance: Subclass and Superclass 333
Public, Private, and Protected Members of a Class 334
Class Methods 336
Static Methods 337
Class Attributes 338
7.3 Advanced Topics in OOP with Python 340
Dunder Methods in Class Definition 340
Using Class as Decorator 346
Built-In
Property() Function and Property Decorator 348
Creating a New Class Dynamically and Modify a Defined
Class or Instance 352
Keeping Objects in Permanent Storage 356
Chapter Summary 358
Exercises 359
Project 361
Chapter 8 Modules and Packages 363
Learning Objectives 363
8.1 Creating Modules and Packages 364
8.2 Using Modules and Packages 367
8.3 Install and Learn About Modules Developed by Others 369
8.4 Module for Generating Random Numbers 377
Functions for Bookkeeping 379
Functions for Generating Random Integers 379
Functions for Randomly Generating Float Numbers 380
Functions for Randomly Selected Item(s) from Sequences 382
8.5 Module for Mathematical Operations 385
8.6 Modules for Time, Date, and Calendar 395
The Datetime Module 395
The Time Module 405
The Calendar Module 410
8.7 Modules for Data Representation and Exchange 415
8.8 Modules for Interfacing Operating Systems and Python
Interpreter 418
OS Module for Interacting with the Operating System 418
The path Submodule from os for Manipulating File Paths 423
The sys Module for Interaction Between the Python and
Python Interpreter or Python Virtual Machine (PVM) 426
8.9 Module for Logging Events During Program Runtime 434
8.10 Modules for Playing and Manipulating Audio and
Video Files 436
winsound 436
PyGame 439
8.11 Modules for Creating and Manipulating Graphics and
Images 442
Create Graphics with Tkinter 443
Manipulate Images with Pillow 448
8.12 Modules for Data Analytics 451
Chapter Summary 455
Exercises 456
Projects 457
Chapter 9 Develop GUI-Based
Applications 459
Learning Objectives 459
9.1 Terminal-Based
Applications Versus GUI-Based
Applications 460
9.2 Designing and Developing GUI-Based
Applications
in Python 461
Tkinter Module 463
tkinter.ttk—Tk-
Themed
Widgets 475
Chapter Summary 482
Exercises 483
Projects 484