|
源代码:
class Ball:
def __init__(self,color,size):
self.color=color
self.size=size
color=str(color)
size=str(size)
def __str__(self):
msg="I have a:",self.size+self.color,"ball"
return msg
myball=Ball("red","small")
print(myball)
结果:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\python\10.11 01.py", line 11, in <module>
print(myball)
TypeError: __str__ returned non-string (type tuple)
请问怎么将myball改成str类型?
myball=str(myball)不行
|
|