Concatening string and integer
Anthony J Wilkinson
anthony at dstc.edu.au
Fri Apr 28 04:56:53 EDT 2000
On Thu, 27 Apr 2000, Pete Shinners wrote:
> you can also use the back ticks as a shortcut for the str()
> builtin. you can do it like this;
>
> strTemp = "I make a test number: " + `iMyNumber` + " once again"
Actually the back ticks appear to be a shortcut for repr() not str()
which in the above case give the same result but won't for all objects,
for example:
>>> class aclass:
... def __str__(self):
... return 'spam'
...
>>> a = aclass()
>>> `a`
'<__main__.aclass instance at f93a8>'
>>> str(a)
'spam'
>>> repr(a)
'<__main__.aclass instance at f93a8>'
Cheers,
Anthony
_____________________________________________________________________
Anthony J Wilkinson anthony at dstc.edu.au
Software Engineer http://www.fnorb.com
DSTC Pty Ltd Ph: +61 7 3365 4310
More information about the Python-list
mailing list