擅长:python、mysql、java
<p>如果遵循<a href="https://stackoverflow.com/questions/59441499/how-to-more-quickly-make-a-bunch-of-objects-in-python#comment105066711_59441499">@kaya3's advice</a>并重新设计<code>ChessPiece</code>类,则可以很容易地使用列表理解,例如(使用<a href="https://en.wikipedia.org/wiki/Algebraic_notation_(chess)#Naming_the_pieces" rel="nofollow noreferrer">abbreviations</a>并忽略数字):</p>
<pre><code>color = 'W'
non_pawns = [ChessPiece(color, c) for c in 'RNBKQBNR']
pawns = [ChessPiece(color, 'P') for _ in range(8)]
</code></pre>