a problem about "print"

Harrison Morgan harrison.morgan at gmail.com
Wed Jul 4 06:31:31 CEST 2012

On Wed, Jul 4, 2012 at 12:16 AM, levi nie <levinie001 at gmail.com> wrote:

> print "aList is "+string(aList) ?
> 2012/7/4 levi nie <levinie001 at gmail.com>
>> aList is a list.i want to get the output seem this "aList is
>> [x,x,x,x,x,x,x,x,x]"
>> how can i get this?
>> it's wrong when i write this, print "aList is "+[x,x,x,x,x,x,x,x,x]
> --
> http://mail.python.org/mailman/listinfo/python-list
Try this:

print "aList is", aList

That shows it like your example. The problem with how you were trying it
is, you have a string and a list and you're trying to combine (concatenate)
them. That doesn't work. One way to get around that is to change the list
into a string, like your second post (it would be str(aList), by the way).
By separating them with a comma instead of a plus, the print statement does
that for you, and also inserts a space in-between them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120704/6cbfd816/attachment.html>

More information about the Python-list mailing list