[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
So, What’s Python? As discussed, this book won’t devote much space to Python fundamentals, and we’ll defer an abstract discussio ...
...
PART I The Beginning This part of the book gets things started by taking us on a quick tour that reviews Python fundamental prer ...
...
CHAPTER 1 A Sneak Preview “Programming Python: The Short Story” If you are like most people, when you pick up a book as large as ...
Readers of the Fourth Edition of Learning Python might recognize some aspects of the running example used in this chapter—the ch ...
We’ve just made two records, albeit simple ones, to represent two people, Bob and Sue (my apologies if you really are Bob or Sue ...
A database list Of course, what we’ve really coded so far is just two variables, not a database; to collect Bob and Sue into a u ...
just fleeting objects in memory that will disappear once we exit Python. For another, every time we want to extract a last name ...
Bob Smith 10000 Sue Jones 20000 >>> [person[0][1] for person in people] # collect names ['Bob Smith', 'Sue Jones'] > ...
Using Dictionaries The list-based record representations in the prior section work, though not without some cost in terms of per ...
and by zipping together name/value lists: >>> names = ['name', 'age', 'pay', 'job'] >>> values = ['Sue Jones', ...
Interestingly, tools such as list comprehensions and on-demand generator expressions can even approach the utility of SQL querie ...
Because this record contains nested structures, we simply index twice to go two levels deep: >>> bob2['name'] # bob's f ...
Notice how this structure allows us to access a record directly instead of searching for it in a loop—we get to Bob’s name immed ...
>>> x ['Bob Smith', 'Sue Jones'] And to add a new record, simply assign it to a new key; this is just a dictionary, aft ...
Example 1-1. PP4E\Preview\initdata.py initialize data to be stored in files, pickles, shelves records bob = {'name': 'Bob Smith' ...
Similarly, the label that precedes every example file’s code listing tells you where the source file resides in the examples pa ...
Example 1-2. PP4E\Preview\make_db_file.py """ Save in-memory database object to a file with custom formatting; assume 'endrec.', ...
you’re running these examples (as is, the database file shows up in the current working directory): ...\PP4E\Preview> python ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf