string concatenate

D'Arcy J.M. Cain darcy at druid.net
Wed Oct 1 18:54:03 CEST 2008


On Wed, 1 Oct 2008 09:41:57 -0700 (PDT)
sandric ionut <sandricionut at yahoo.com> wrote:
> Hi:
> 
> I have the following situation:
>     nameAll = []
>     for i in range(1,10,1):
>         n = "name" + str([i])
>         nameAll += n
>     print nameAll
> 
> I get:
> 
> ['n', 'a', 'm', 'e', '[', '1', ']', 'n', 'a', 'm', 'e', '[', '2', ']', 'n', 'a', 'm', 'e', '[', '3', ']', 'n', 'a', 'm', 'e', '[', '4', ']', 'n', 'a', 'm', 'e', '[', '5', ']', 'n', 'a', 'm', 'e', '[', '6', ']', 'n', 'a', 'm', 'e', '[', '7', ']', 'n', 'a', 'm', 'e', '[', '8', ']', 'n', 'a', 'm', 'e', '[', '9', ']']
> 
> but I would like to have it as:
> 
> name1 name2 name3 ...name10

nameAll = ["name%d" % x for x in range(1,10,1)]

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list