String question

Trent Mick trentm at ActiveState.com
Wed Feb 16 07:31:06 EST 2000


> 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?

Like this:
>>>
>>> n = 10
>>> s = "n = " + str(n)
>>> s
'n = 10'

And, by the way, 'string' is probably a bad variable name (presuming you may
want to import the string module sometime).

Trent







More information about the Python-list mailing list