[Tutor] Converting a numerical variable into a string variable

Andres Sanchez telmo_andres at yahoo.com
Thu Feb 12 21:06:26 CET 2009


Folks,

Please, give me a hand with this. Say I have a vector defined as x=[1,2,3,4,...,9]. I need to write string variables with the names G1BF....G9BF. Thus, the first string variable would be 'G'+'1'+'BF', being the number 1 equal to x[0]. Now, using a for loop, I want to do something like: y[i]='G'+x[i-1]+'BF' , to create my string variables. Yes, the problem is that I am mixing numerical and string variables and Python reports an error when I try to do this. So, the question is: how do I do to convert the numerical variable x[0]=1 into a string variable '1', so I can do my 'G'+'1'+BF' thing?

Your thoughts are appreciated.

By the way, 'G'+'x[0]'+'BF' reports 'Gx[0]BF'  :)

Regards,

Andres


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090212/d7e2ed90/attachment.htm>


More information about the Tutor mailing list