Re: string concatenate

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D'Arcy J.M. Cain

    Re: string concatenate

    On Wed, 1 Oct 2008 09:41:57 -0700 (PDT)
    sandric ionut <sandricionut@y ahoo.comwrote:
    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@druid.ne t | 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.
Working...