美文网首页
python函数变量*arg示例

python函数变量*arg示例

作者: 修玛哦 | 来源:发表于2019-03-28 10:39 被阅读0次

    在传入可变参数时传入后参数为tuple

    class Student(object):
        def __init__(self, name, score):
            self.name = name
            self.score = score
        def print_score(self,*testcha):
            print('%s:%s'%(self.name,self.score))
    #注意:此处无需对testcha长度进行判断
            for i in testcha:
                print('%s'%i)
    
    wang=Student('wang',21)
    wang.print_score()
    
    

    相关文章

      网友评论

          本文标题:python函数变量*arg示例

          本文链接:https://www.haomeiwen.com/subject/sxgfbqtx.html