[Tutor] How to test for a remainder from division

Kent Johnson kent37 at tds.net
Tue May 15 16:14:59 CEST 2007


Matt Smith wrote:
>> Here is the implementation of calendar.isleap():
>>
>> def isleap(year):
>>      """Return 1 for leap years, 0 for non-leap years."""
>>      return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
> 
> Hi Kent,
> 
> Thanks for the help. For future reference how do I go look at the
> implementation of a particular function (the ones coded in Python, I
> don't know C)?

Look in the lib directory that was installed with Python. The location 
varies. On Windows look for C:\Python2.x\Lib. My Mac has it at
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5

In the python interpreter, try
 >>> import sys
 >>> sys.path

The lib directory will be listed as one element of sys.path.

Kent


More information about the Tutor mailing list