using floats/ints in print and write

Joonas Paalasmaa joonas at olen.to
Mon Aug 20 20:56:30 CEST 2001


Rajarshi Guha wrote:
> 
> Hi,
>   does'nt python 2.2 allow me to use float/int variables in a string
> context. That is I can't write:
> 
> print a + 'hello'
> 
> where a is float or int. Right now I'm using fpformat.fix() to get a string
> value. Is there any other way?

Here are two preferred ways to do that.

>>> a = 3
>>> print str(a)+"hello"
3hello
>>> print `a`+"hello"
3hello

You can also print them as separate arguments, but
then Python prints a space between them.

>>> print a, "hello"
3 hello
>>>



More information about the Python-list mailing list