Learning Python: Powerful Object-Oriented Programming
Format: PDF / Kindle (mobi) / ePub
Google and YouTube use Python because it's highly adaptable, easy to maintain, and allows for rapid development. If you want to write high-quality, efficient code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly -- whether you're new to programming or just new to Python. It's an easy-to-follow self-paced tutorial, based on author and Python expert Mark Lutz's popular training course.
Each chapter contains a stand-alone lesson on a key component of the language, and includes a unique Test Your Knowledge section with practical exercises and quizzes, so you can practice new skills and test your understanding as you go. You'll find lots of annotated examples and illustrations to help you get started with Python 3.0.
Learn about Python's major built-in object types, such as numbers, lists, and dictionariesCreate and process objects using Python statements, and learn Python's general syntax modelStructure and reuse code using functions, Python's basic procedural toolLearn about Python modules: packages of statements, functions, and other tools, organized into larger componentsDiscover Python's object-oriented programming tool for structuring codeLearn about the exception-handling model, and development tools for writing larger programsExplore advanced Python tools including decorators, descriptors, metaclasses, and Unicode processing
back: >>> 'hello world' # Interactive echoes 'hello world' Really, the print statement is just an ergonomic feature of Python—it provides a simple interface to the sys.stdout object, with a bit of default formatting. In fact, if you like to work harder than you must, you can also code print operations this way: >>> import sys # Printing the hard way >>> sys.stdout.write('hello world\n') hello world 230 | Chapter 11: Assignment, Expressions, and print This code explicitly calls
integer code): >>> ord('s') 115 Now, suppose we wish to collect the ASCII codes of all characters in an entire string. Perhaps the most straightforward approach is to use a simple for loop, and append the results to a list: >>> res =  >>> for x in 'spam' : ... res.append(ord(x)) ... >>> res [115, 112, 97, 109] Now that we know about map, though, we can achieve similar results with a single function call without having to manage list construction in the code: >>> res = map(ord,
runtime engine of Python; it’s always present as part of the Python system, and it’s the component that truly runs your scripts. Technically, it’s just the last step of what is called the “Python interpreter.” Figure 2-2 illustrates the runtime structure described here. Keep in mind that all of this complexity is deliberately hidden from Python programmers. Byte code compilation is automatic, and the PVM is just part of the Python system that you have installed on your machine. Again,
control jumps immediately to a handler when an exception occurs, there’s no need to instrument all your code to guard for errors. Moreover, because Python detects errors automatically, your code usually doesn’t need to check for errors in the first place. The upshot is that exceptions let you largely ignore the unusual cases and avoid error-checking code. with/as Context Managers | 599 Notice that this class’ _ _exit_ _ method returns False to propagate the exception; deleting the
search path The sys.path list Module file selection Advanced module selection concepts 2. Compile It (Maybe) 3. Run It Chapter Summary Quiz Answers Module Coding Basics Module Creation Module Usage The import Statement The from statement The from * Statement Imports Happen Only Once import and from Are Assignments Cross-File Name Changes import and from Equivalence Potential Pitfalls of the from Statement When import is required Module Namespaces Files Generate