O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required