Skip to main content
 首页 » 编程设计

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

2025年05月04日43bluestorm

<分区>

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)