String question
Alan Daniels
daniels at mindspring.com
Wed Feb 16 19:52:03 EST 2000
On Wed, 16 Feb 2000 20:59:38 +0100, the infinitely wise Runar Olsen
(runaro at stud.cs.uit.no) spoke forth to us, saying...
[snip]
>I want the variable 'string' to be a string and not a list..
>>>> n =10
>>>> string = "n = ", n
>>>> print string
>('n = ', 10)
>
>I want string to be "n = 10". How?
By having that comma in there, right after "n = ", you're telling
Python that you want "string" to be a tuple, not a string. Properly,
what you want is:
x = "n = " + str(n)
or,
x = "n = %d" % n
Note I'm naming the variable x here, because "string" is a standard
Python module, hence having a variable with the same name is a bad
idea (even though its allowed). Read the Python docs on tuples for a
better idea of what your code is doing.
--
=======================
Alan Daniels
daniels at mindspring.com
daniels at cc.gatech.edu
More information about the Python-list
mailing list