[Tutor] Why does print add spaces ?

Michael Barrett mike@daboyz.org
Tue Mar 18 03:33:01 2003


Using list comprehension you could do the following:

>>> x = 'abcdefghi'
>>> print ','.join([i for i in x])
a,b,c,d,e,f,g,h,i

As to why python prints the spaces?  It's just the way print works in the language.  Can't really answer why, but I'm sure the developers felt they had a reason.

Sorry I couldn't be more help.

On Sat, Mar 15, 2003 at 01:48:44PM -0800, Tony Cappellini wrote:
> 
> 
> In this example
> 
> 
> mystr="abcdefghi"
> 
> for x in range(1,len(mystr)):
>    print "%s," % mystr[x],
> 
> 
> a, b, c, d, e, f, g, h, i,
> 
> why does print add an implied space ??
> How would i change this if I didn't want any spaces between each printed 
> character ?
> 
> 

-- 
     ________________________________________________________________________
                Mike Barrett | "I used to read, now I go to raves."
             mike@daboyz.org | -- Random MUNI Rider, speaking
              www.daboyz.org |    to my friend Allison.
     ------------------------+-----------------------------------------------