求解:此段代码为什么没有代码联想
问题:为什么 get_info方法下 info['department'] =self.department.后没有联想出get_name()方法?手敲后运行也会报错提示没有get_name方法.哪儿错了?代码:
#incoding:utf8
class Department:
def __init__(self,name):
self.name = name
def get_name(self):
return self.name
class Employee :
id = 0
def __init__(self,name,phone,salary,department):
Employee.id = Employee.id + 1
self.id = Employee.id
self.name = name
self.phone = phone
self.salary = salary
self.department = department
def get_salary(self):
return self.salary
def get_info(self):
info = {}
info['name']= self.name
info['phone'] = self.phone
info['salary'] = self.salary
info['department'] =self.department.get_name()
return info
hr = Department('hr')
zhangsan = Employee('zhangsan','1314444222','10000',hr)
print zhangsan.get_info()
:victory: 快捷键 学习 编辑器的事情,你应该问编辑器才对 运行一下 为什么提示get_name()不存在,明明已经定义了!!
页:
[1]