[英]Printing a tuple
I have a tuple m = ('ring', 5)
and I want to print it out as ring 5
. 我有一个元组
m = ('ring', 5)
,我想将其打印为ring 5
。
I have tried print %s %f, %m
and I get an error. 我尝试
print %s %f, %m
,但出现错误。 What am I doing wrong? 我究竟做错了什么?
>>> m = ('ring', 5)
what you were trying to do 你想做什么
>>> print "%s %f" % m
ring 5.000000
Except %f
means float
and you want %d
for int
: 除了
%f
表示float
而您想要%d
表示int
:
>>> print "%s %d" % m
ring 5
Use format
it is more elegant 使用
format
更优雅
print '{0} {1}'.format(*m)
https://stackoverflow.com/a/5082482/243431 https://stackoverflow.com/a/5082482/243431
m = ('ring', 5)
print m[0], m[1]
prints 版画
ring 5
>>> m = ('ring', 5)
>>> for element in m:
print element,
ring 5
This might work. 这可能有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.