if self.hour < 12:
standardTime +="AM" else:
standardTime +="PM"
print standardTime
下面是测试这个类的一个小程序
#!/usr/bin/python
# FileName: t702.py
# Description: Creating and manipulating objects of class Time.
# Author: yk
# Date: Sat May 17 04:25:03 CST 2008
from time1 import Time
time = Time()
print"The attributes of time are: " print"time1.hour:",time.hour print"time1.minute:",time.minute print"time1.second:",time.second