Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list printing in formatted string in python

Tags:

python

In python to print a formatted string with ints and strings, I'd usually do :

print '%d %d - %s' %(x,y, mystr)

Is there anything similar for printing out a list? I have:

L= [1,0,0]
name = 'V'

and I want the output to be :

v(1,0,0)

Is there anything similar to %d for list objects?

like image 742
Arnab Datta Avatar asked Jul 06 '26 04:07

Arnab Datta


1 Answers

If you want complete control how the list gets rendered, you'll have to format it separately.

In your case, the code would be something like:

items = [1,0,0]
name = 'V'
formatted = '%s(%s)' % (
    name,
    ','.join(str(it) for it in items)
)
like image 149
millimoose Avatar answered Jul 08 '26 18:07

millimoose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!