Is there any way to pass the whole list in python string format
i=['John','10','A']
t="{:<10}| {:<10}| {:<10}"
print t.format("Name","Age","Grade")
# print t.format(i[0],i[1],i[2])
print t.format(i)
Instead of passing individual list values, I want to pass the whole list
print t.format(['John','10','A'])
but this return IndexError: tuple index out of range
. Is there any way to do this?
Just unpack
the list:
>>> i=['John','10','A']
>>> t="{:<10}| {:<10}| {:<10}"
>>> t.format(*i)
'John | 10 | A '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With