Page 1 of 1

Changing a variable from numerical to string[solved]

Posted: Thu Mar 27, 2008 6:47 pm
by Mr. E
I would like to know if it's possible to assign a numerical variable to a string variable. A sketchy example follows:

Code: Select all

    $ number =+ 7
    $ word = "House" + number
    if word = "House7":
        'It worked!'

Re: Changing a variable from numerical to string

Posted: Thu Mar 27, 2008 6:57 pm
by Wintermoon

Code: Select all

$ word = "House%s" % number # The placeholder-substitution method.
$ word = "House" + str(number) # The simple, direct method.

Re: Changing a variable from numerical to string[solved]

Posted: Thu Mar 27, 2008 7:01 pm
by Mr. E
Thanks for the help, wintermoon. I knew it was simple but it was still bugging me for the last hour or so...