Reputation: 3135
I have a tuple m = ('ring', 5)
and I want to print it out as ring 5
.
I have tried print %s %f, %m
and I get an error. What am I doing wrong?
Upvotes: 1
Views: 157
Reputation: 5629
Use format
it is more elegant
print '{0} {1}'.format(*m)
https://stackoverflow.com/a/5082482/243431
Upvotes: 1
Reputation: 34531
>>> m = ('ring', 5)
>>> for element in m:
print element,
ring 5
This might work.
Upvotes: 0
Reputation: 133764
>>> 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
:
>>> print "%s %d" % m
ring 5
Upvotes: 6