[Tutor] printing 00

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Jul 11 07:45:01 CEST 2006


> I created a function to print the Time object:
>
> def printTime(time):
> 	print "%d:%d:%d" % (time.hours, time.minutes,
> time.seconds)
>
> However, when I type '00', I get the following:
>>>> time = Time(12,34.4,00)
>>>> printTime(time)
> 12:34:0

Hi Chris,

You'll want to check some of the details on "String Formatting" -- there's 
an option to format a number using two (or more) digits:

     http://www.python.org/doc/lib/typesseq-strings.html

Good luck!


More information about the Tutor mailing list