+ 2
Format tuples in python
If I have this: t = (1, 3, 2, 2, 3) f = “{0} {1} {2} {3} {4}”.format(t) it gives an error This is the only way I was able to do it: t = (1, 3, 2, 2, 3) f = “{0} {1} {2} {3} {4}”.format(t[0], t[1], t[2], t[3], t[4]) Any suggestions? If not it’s ok it is just a minor problem
4 odpowiedzi
+ 4
Alternatively you can use format(*t) - the star 'unpacks' your tuple.
+ 4
Another option for the same result, to separate the values by spaces:
f = ' '.join(map(str,t))
+ 3
HonFu that worked thank you!
+ 2
Just write
f = "{}".format(t)