gpt4 book ai didi

python - 如何将字符串和变量赋值给一个变量

转载 作者:太空宇宙 更新时间:2023-11-04 08:44:46 26 4
gpt4 key购买 nike

<分区>

class Bird:
def __init__(self):
self.noise = "chirping"
self.beak = "closed"
self.wings = "closed"
def __str__(self):
msg = "The bird is ", self.noise "its beak is ",
self.beak "its wings are ", self.wings
return msg
mybird = Bird()
print(mybird)

我不完全确定问题出在哪里,但我需要它来打印我的 Bird 对象。

这是 python 给我的错误:

Traceback (most recent call last):

File "D:/000- Python-Coding/Practice/ bird object program.py", line 10, in <module>

print(mybird)

TypeError: __str__ returned non-string (type tuple)

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com