[Tutor] Format problem

Alan Gauld alan.gauld at yahoo.co.uk
Tue Oct 20 12:32:44 EDT 2020


Please always reply to the list using ReplyAll or ReplyList according to
your mail program.

On 20/10/2020 15:07, P L wrote:
> I thought by server=Server() would make it call the __str__


No, __str__() is the function called any time Python has to convert
your server instances to a string. The main use of that being when
we call print() - because print converts all its arguments to str().



> So that means I have to directly put the __str__ in the
> variable instance load().


No, that would result in load have strings to deal with but it uses
numbers and that's how it should be!



> I'm not sure how to format my output total to two decimals.


You have done it correctly, you just aren't using it because you are not
printing a server object.


-- 

Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list