程式碼如下:
## -*- 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)
運行結果:
##我的問題:
系統提示:return ("房子的戶主是:%s,面積是:%d平米,地址是:%s,戶型是:%s。" %(self.name,self.area,self.addr,self.info))
她說我這段話裡找不到name這個屬性,可是我明明在init裡面寫了。裡裡外外檢查了很多遍也看不明白。
给我你的怀抱2017-06-15 09:23:38
def __init__(self,new_name,new_area,new_addr,new_info):
self.name = new_name
self.area = new_area
self.addr = new_addr
self.info = new_info
需要對self
物件添加屬性.並不是寫了就有了.