code show as below:
# -*- coding:gb2312 -*- class Home: def __init__(self,new_name,new_area,new_addr,new_info): name = new_name area = new_area addr = new_addr info = new_info def __str__(self): return ("房子的户主是:%s,面积是:%d平米,地址是:%s,户型是:%s。"%(self.name,self.area,self.addr,self.info)) class Bed: def __init__(self): pass def __str__(self): pass fangzi = Home("谢霆锋",182,"香港","三室一厅") print(fangzi)
operation result:
My question:
The system prompts: return ("The owner of the house is: %s, the area is: %d square meters, the address is: %s, and the house type is: %s." %(self.name,self.area,self.addr,self.info))
She said that the attribute name cannot be found in this paragraph, but I clearly wrote it in init. I checked it inside and out many times but still can't figure it out.
You need to add attributes to the
self
object. It doesn’t just have to be written.