class MakeMoney: highSchoolDegree = '' knowledgeReserves = '' personalQualities = '' strongHeart = '' def __init__(self,highSchoolDegree,knowledgeReserves): self.highSchoolDegree = highSchoolDegree self.knowledgeReserves = knowledgeReserves def __str__(self): return "MakeMoney needed: highSchoolDegree: %s,\t knowledgeReserves: %s " % ( self.highSchoolDegree, self.knowledgeReserves) def printGoal(): mm = MakeMoney('本科', '计算机') print(mm) if __name__ == '__main__': printGoal()
同样MakeMoney,python相对来说是这样做的
但是奇怪的是,如果将python的变量注释掉,同样可以得到相同的结果
class MakeMoney: def __init__(self, highSchoolDegree, knowledgeReserves): self.highSchoolDegree = highSchoolDegree self.knowledgeReserves = knowledgeReserves def __str__(self): return "MakeMoney needed: highSchoolDegree: %s,\t knowledgeReserves: %s " % ( self.highSchoolDegree, self.knowledgeReserves) def printGoal(): mm = MakeMoney('本科', '计算机') print(mm) if __name__ == '__main__': printGoal()
结果
MakeMoney needed: highSchoolDegree: 本科, knowledgeReserves: 计算机
同样的事情放在.java文件中就不可能通过编译了