再看Java基础 - 换个方式看Java ~ 1

2021/12/28 17:09:57

本文主要是介绍再看Java基础 - 换个方式看Java ~ 1,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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文件中就不可能通过编译了



这篇关于再看Java基础 - 换个方式看Java ~ 1的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程