- __ STR __ is python to a method of object base class , i.e. python have all classes ;
- Of course django class has the modle ;
- We usually create a class of objects, Print the object when will generally be <__ main_ .TestClass Object AT 0x7f4126578828>, that is the object of their class and memory address ;
- We rewrite the class __ str __ method after can upon print to get the desired information on easy-to-read person objects , the following are examples
# General class the TestClass: DEF the __init__ (Self): the self.name = ' TestCase ' T = the TestClass () Print (T) # give <__ __ main AT 0x7f8c49b21828 the TestClass Object.>
# Rewriting method __str__ class the TestClass: DEF the __init__ ( Self): the self.name = ' TestCase ' DEF __str__ (Self): return the self.name T = the TestClass () Print (T) # Get testcase