python类成员可以外部访问吗_在Python中如何从一个类访问另一个类的成员?

class courseInfo(object):

def __init__(self, courseName):

self.courseName = courseName

self.psetsDone = []

self.grade = "No Grade"

def setGrade(self, grade):

if self.grade == "No Grade":

self.grade = grade

def getGrade(self):

return self.grade

class abc(object):

def __init__(self, courses):

self.myCourses = []

self.Pset = []

self.grade = {}

for course in courses:

self.myCourses.append(courseInfo(course))

def setGrade(self, grade, course="6.01x"):

"""

grade: integer greater than or equal to 0 and less than or

equal to 100

course: string

This method sets the grade in the courseInfo object named

by `course`.

If `course` was not part of the initialization, then no grade is

set, and no error is thrown.

The method does not return a value.

"""

def getGrade(self, course="6.02x"):

"""

course: string

This method gets the grade in the the courseInfo object

named by `course`.

returns: the integer grade for `course`.

If `course` was not part of the initialization, returns -1.

"""

xyz = abc( ["6.00x","6.01x","6.02x"] )

xyz.setGrade(100)

print xyz.getGrade(course="6.01x")

print Xyz.getGrade(course="6.02x")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值