Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

doctest

The doctest module examines documentation strings for text fragments that look like interactive Python sessions. These fragments are then executed and verified to see if they produce the output shown. Here is a short example:

 def gcd(x,y): """ Computes the greatest common divisor of x and y. For example: >>> gcd(40,16) 8 >>> gcd(24,15) 3 >>> gcd(12,85) 1 Both arguments must be positive integers. >>> gcd(3.5,4.2) Traceback (most recent call last): ... TypeError: Arguments must be integers >>> gcd(-4,7) Traceback (most recent call last): ... ValueError: Arguments must be positive integers Long integers may also be used. In this case, the returned value is also a long. >>> gcd(23748928388L, 6723884L) 4L """ if not (isinstance(x,(int,long)) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book