Hi:Here you defined nameAll as a list
I have the following situation:
Â*Â*Â* nameAll = []
Â*Â*Â* for i in range(1,10,1):That range is superfluous, you could write this instead[1]:
for i in range(10):
Â*Â*Â*Â*Â*Â*Â* n = "name" + str([i])in this, you're converting a list into a string. If i was 2, the
conversion result into: 'name' + '[2]'
Â*Â*Â*Â*Â*Â*Â* nameAll += nHere you're appending n into the list nameAll. Python's string behaves
like a list, that it is iterable, so list accepts it.
Â*Â*Â* print nameAllyour code should be:
listAll = []
for i in range(1, 11):
n = "name" + str(i)
listAll.append(n)
print ' '.join(listAll)
or using list comprehension and string interpolation:
print ' '.join('name%s' % i for i in range(1, 11))
[1] Note that range(10) starts with 0, and produces a list of 10 numbers.
If, like in your expected result, you want name1 till name10, you'll need
range(1, 11) because range is half-open, it includes 1, but not 11. This
behavior has some unique property that simplifies many things, although
it do takes some time to get used to.