repr方法字符串输出实例对象的值

Posted themost

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了repr方法字符串输出实例对象的值相关的知识,希望对你有一定的参考价值。

#coding=utf-8
#repr方法字符串输出实例对象的值
class CountFromBy(object):

    def __init__(self, val=0, incr=1):
        self.val = val
        self.incr = incr

    def increase(self):
        self.val += self.incr

    def __repr__(self):
        return str(self.val)


>>> c = CountFromBy()
>>> c
0

 

以上是关于repr方法字符串输出实例对象的值的主要内容,如果未能解决你的问题,请参考以下文章