擅长:python、mysql、java
<p>您可以向类中添加<code>__str__()</code>方法:</p>
<pre><code>class wow():
def __init__(self):
self.num=r.randint(0,10)
def __str__(self):
return str(self.num)
</code></pre>
<p>然后只需打印:</p>
<pre><code>print(*a)
</code></pre>
<p>您将获得:</p>
<pre><code>3 9 4 9 3
</code></pre>
<p>此外,阅读此<a href="https://www.journaldev.com/22460/python-str-repr-functions#:~:text=Python%20__str__(),is%20invoked%20on%20an%20object.&text=If%20we%20don't%20implement,calls%20__repr__()%20function." rel="nofollow noreferrer">Link</a>可能有助于获得更好的线索:</p>