This third revision of Manning's popular The Quick Python Book offers a clear, crisp updated introduction to the elegant Python programming language and its famously easy-to-read syntax. Written for programmers new to Python, this latest edition includes new exercises throughout. It covers features common to other languages concisely, while introducing Python's comprehensive standard functions library and unique features in detail.
Foreword by Nicholas Tollervey, Python Software Foundation.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
About the Technology
Initially Guido van Rossum's 1989 holiday project, Python has grown into an amazing computer language. It's a joy to learn and read, and powerful enough to handle everything from low-level system resources to advanced applications like deep learning. Elegantly simple and complete, it also boasts a massive ecosystem of libraries and frameworks. Python programmers are in high demand/mdash;you can't afford not to be fluent!
About the Book
The Quick Python Book, Third Edition is a comprehensive guide to the Python language by a Python authority, Naomi Ceder. With the personal touch of a skilled teacher, she beautifully balances details of the language with the insights and advice you need to handle any task. Extensive, relevant examples and learn-by-doing exercises help you master each important concept the first time through. Whether you're scraping websites or playing around with nested tuples, you'll appreciate this book's clarity, focus, and attention to detail.
What's Inside
Clear coverage of Python 3
Core libraries, packages, and tools
In-depth exercises
Five new data science-related chapters
Author(s): Naomi Ceder
Edition: 3rd
Publisher: Manning
Year: 2018
Language: English
Pages: 460
Tags: Python;Programming;
brief contents......Page 3
contents......Page 5
foreword......Page 15
preface......Page 16
about this book......Page 17
Why should I use Python?......Page 23
What Python does well......Page 24
What Python doesn’t do as well......Page 27
Summary......Page 29
Start......Page 31
Installing Python......Page 32
Basic interactive mode and IDLE......Page 33
Using IDLE’s Python shell window......Page 35
Using the interactive prompt to explore Python......Page 37
Summary......Page 38
Quick Python overview......Page 40
Built-in data types......Page 41
Control flow structures......Page 48
Module creation......Page 51
Object-oriented programming......Page 52
Summary......Page 54
--- Essentials......Page 55
Indentation and block structuring......Page 56
Variables and assignments......Page 58
Expressions......Page 60
Strings......Page 61
Numbers......Page 62
Getting input from the user......Page 65
Basic Python style......Page 66
Summary......Page 67
Lists, tuples & sets......Page 68
List indices......Page 69
Modifying lists......Page 71
Sorting lists......Page 74
Other common list operations......Page 76
Nested lists and deep copies......Page 79
Tuples......Page 81
Sets......Page 85
Summary......Page 86
Strings as sequences of characters......Page 87
Basic string operations......Page 88
Special characters and escape sequences......Page 89
String methods......Page 91
Converting from objects to strings......Page 100
Using the format method......Page 101
Formatting strings with %......Page 103
String interpolation......Page 105
Bytes......Page 106
Summary......Page 107
Dictionaries......Page 108
What is a dictionary?......Page 109
Other dictionary operations......Page 110
Word counting......Page 113
What can be used as a key?......Page 114
Sparse matrices......Page 115
Dictionaries as caches......Page 116
Summary......Page 117
The while loop......Page 118
The if-elif-else statement......Page 119
The for loop......Page 120
List and dictionary comprehensions......Page 123
Statements, blocks, and indentation......Page 125
Boolean values and expressions......Page 128
Writing a simple program to analyze a text file......Page 130
Summary......Page 131
Basic function definitions......Page 132
Function parameter options......Page 134
Mutable objects as arguments......Page 137
Local, nonlocal, and global variables......Page 138
Assigning functions to variables......Page 140
Generator functions......Page 141
Decorators......Page 143
Summary......Page 144
What is a module?......Page 146
A first module......Page 147
The import statement......Page 150
The module search path......Page 151
Private names in modules......Page 152
Library and third-party modules......Page 153
Python scoping rules and namespaces......Page 154
Summary......Page 160
Python programs......Page 161
Creating a very basic program......Page 162
Making a script directly executable on UNIX......Page 167
Script execution options in Windows......Page 168
Programs and modules......Page 169
Distributing Python applications......Page 174
Summary......Page 175
Using the filesystem......Page 177
Paths and pathnames......Page 178
Getting information about files......Page 186
More filesystem operations......Page 187
Processing all files in a directory subtree......Page 190
Summary......Page 191
Opening files and file objects......Page 194
Opening files in write or other modes......Page 195
Functions to read and write text or binary data......Page 196
Reading and writing with pathlib......Page 198
Screen input/output and redirection......Page 199
Reading structured binary data with the struct module......Page 201
Pickling objects files......Page 203
Shelving objects......Page 206
Summary......Page 208
Exceptions......Page 209
Introduction to exceptions......Page 210
Exceptions in Python......Page 213
Context managers using the with keyword......Page 222
Summary......Page 223
--- Advanced Language Features......Page 224
Classes & OOP......Page 225
Defining classes......Page 226
Instance variables......Page 227
Methods......Page 228
Class variables......Page 229
Static methods and class methods......Page 232
Inheritance......Page 234
Inheritance with class and instance variables......Page 236
Recap: Basics of Python classes......Page 237
Private variables and private methods......Page 239
Using @property for more flexible instance variables......Page 240
Scoping rules and namespaces for class instances......Page 241
Destructors and memory management......Page 245
Multiple inheritance......Page 246
Summary......Page 248
Regular expressions......Page 249
Regular expressions with special characters......Page 250
Regular expressions and raw strings......Page 251
Extracting matched text from strings......Page 253
Substituting text with regular expressions......Page 256
Summary......Page 258
Data types as objects......Page 259
Types and user-defined classes......Page 260
What is a special method attribute?......Page 263
Making an object behave like a list......Page 264
The __getitem__ special method attribute......Page 265
Giving an object full list capability......Page 267
Subclassing from built-in types......Page 270
Summary......Page 272
What is a package?......Page 273
A first example......Page 274
A concrete example......Page 275
The __all__ attribute......Page 279
Proper use of packages......Page 280
Summary......Page 281
Python libraries......Page 282
“Batteries included”: The standard library......Page 283
Moving beyond the standard library......Page 287
Installing Python libraries using pip and venv......Page 288
Summary......Page 290
--- Data......Page 291
The problem: The never-ending flow of data files......Page 292
Scenario: The product feed from hell......Page 293
More organization......Page 295
Saving storage space: Compression and grooming......Page 296
Summary......Page 299
Processing data files......Page 300
Reading text files......Page 301
Excel files......Page 309
Data cleaning......Page 311
Writing data files......Page 314
Summary......Page 316
Fetching files......Page 317
Fetching data via an API......Page 321
Structured data formats......Page 323
Scraping web data......Page 331
Summary......Page 335
Saving data......Page 336
SQLite: Using the sqlite3 database......Page 337
Using MySQL, PostgreSQL, and other relational databases......Page 339
Making database handling easier with an ORM......Page 340
key:value stores with Redis......Page 347
Documents in MongoDB......Page 350
Summary......Page 353
Python tools for data exploration......Page 354
Jupyter notebook......Page 355
Python and pandas......Page 358
Data cleaning......Page 360
Data aggregation and manipulation......Page 365
Why you might not want to use pandas......Page 369
Summary......Page 370
Downloading the data......Page 371
Parsing the inventory data......Page 375
Selecting a station based on latitude and longitude......Page 376
Selecting a station and getting the station metadata......Page 378
Parsing the weather data......Page 381
Saving the weather data in a database (optional)......Page 385
Using pandas to graph your data......Page 386
A.1 Accessing Python documentation on the web......Page 388
A.2 Best practices: How to become a Pythonista......Page 391
A.3 PEP 8—Style guide for Python code......Page 393
A.4 Comments......Page 398
A.5 The Zen of Python......Page 406
B.1 Chapter 4......Page 408
B.2 Chapter 5......Page 410
B.3 Chapter 6......Page 413
B.4 Chapter 7......Page 416
B.5 Chapter 8......Page 418
B.6 Chapter 9......Page 420
B.7 Chapter 10......Page 423
B.8 Chapter 11......Page 424
B.9 Chapter 12......Page 425
B.10 Chapter 13......Page 426
B.11 Chapter 14......Page 429
B.12 Chapter 15......Page 431
B.13 Chapter 16......Page 435
B.14 Chapter 17......Page 436
B.16 Chapter 20......Page 438
B.17 Chapter 21......Page 440
B.18 Chapter 22......Page 441
B.19 Chapter 23......Page 444
B.20 Chapter 24......Page 446
Index......Page 448