using floats/ints in print and write

Frederic Giacometti fred at arakane.com
Mon Aug 20 14:57:45 EDT 2001


"Rajarshi Guha" <rajarshi at seed.chem.psu.edu> wrote in message
news:9lrm06$ausj5$1 at ID-91520.news.dfncis.de...
> 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?

Try these, and take the one you prefer:

print a, 'hello'

print '%s %s' % (a, 'hello')

print '%i %s' % (a, 'hello')

print `a` + 'hello'

print str( a) + 'hello'

....






More information about the Python-list mailing list