Return a tuple of arguments to be fed to string.format()

末鹿安然 提交于 2019-11-28 20:09:31
print('Two pair, {0}s and {1}s'.format(*cards))

You are missing only the star :D

Format is preferred over the % operator, as of its introduction in Python 2.6: http://docs.python.org/2/library/stdtypes.html#str.format

It's also a lot simpler just to unpack the tuple with * -- or a dict with ** -- rather than modify the format string.

Andrew Grant

This attempts to use "cards" as single format input to print, not the contents of cards.

Try something like:

print('Two pair, %ss and %ss' % cards)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!