擅长:python、mysql、java
<p>重写<code>__add__</code>:</p>
<pre><code>class oObject (object):
def __init__(self, value):
self.value = value
def __str__(self):
return str(self.value)
def __repr__(self):
return str(self.value)
def __add__(self,val):
return str(self.value)+val
new = oObject(50)
'''if I use print it's Okay'''
print new
'''But if i try to do something like that ...'''
print new + '.kine' #prints 50.kine
</code></pre>