3、用Python设计一个课程类,包括课程编号、课程名称、任课教师、上课地点 等属性,把上课地点变量设为私有的,增加构造方法和显示课程信息的方法。
时间: 2024-06-04 07:12:02 浏览: 103
python数据分析 课设
class Course:
def __init__(self, code, name, teacher, location):
self.code = code
self.name = name
self.teacher = teacher
self.__location = location
def display_info(self):
print("课程编号: ", self.code)
print("课程名称: ", self.name)
print("任课教师: ", self.teacher)
print("上课地点: ", self.__location)
c = Course("001", "Python编程", "张老师", "A101")
c.display_info()
阅读全文