Use python class of __int__ and __str__

class F.: 

DEF __str __ (Self):
return 'Hello China'

DEF __int __ (Self):
return 123

RES = F. ()
Print (STR (RES)) # result Hello China
Print (int (RES)) # result 123

when the object we use str conversion classes created, it will automatically look for class __str__ function,
when the object we use int conversion classes created, it will automatically look for class __int__ function

Guess you like

Origin www.cnblogs.com/jinbaobao/p/12049464.html