假设我有一个值说Player 1和 Player 2。我可以将它们分配给单个变量吗?
print("%s choose this piece" %Player_value)
Run Code Online (Sandbox Code Playgroud)
预期产出
Player 1 choose this value
Player 2 choose this value
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点!
请帮忙!
>>> import itertools
>>> player = itertools.cycle(['Player 1', 'Player 2'])
>>> print("%s choose this piece" % next(player))
Player 1 choose this piece
>>> print("%s choose this piece" % next(player))
Player 2 choose this piece
>>> print("%s choose this piece" % next(player))
Player 1 choose this piece
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1242 次 |
| 最近记录: |