print '%d:%02d' % divmod(10,20)
結果我想要的東西:蟒蛇元組打印問題
0:10
然而
print '%s %d:%02d' % ('hi', divmod(10,20))
結果:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
print '%s %d:%02d' % ('hi', divmod(10,20))
TypeError: %d format: a number is required, not tuple
我如何解決第二個打印語句,這樣它的工作原理?
我想有一個比
m = divmod(10,20)
print m[0], m[1]
或使用python 3或格式()簡單的解決方案。
我覺得我失去了一些東西明顯
從:http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python 打印 「這是一個元組:%S」 %(divmod(10, 20),) – sihrc
我認爲這是一個很好的問題。沒什麼明顯的!在我看來,非常微妙。非常豐富。 – Jiminion