Question about output...

Grant Edwards grante at visi.com
Wed Oct 16 22:37:18 EDT 2002


In article <m3d6q9kddt.fsf at ferret.object-craft.com.au>, Dave Cole wrote:

>Tony> cout << "The average of " << firstInt << " and " << secondInt <<
>Tony> " is " << average << endl;

>>>> firstInt = 10
>>>> secondInt = 20
>>>> average = (firstInt + secondInt) / 2
>>>> print 'The average of', firstInt, 'and', secondInt, 'is', average
> The average of 10 and 20 is 15

Or sys.stdout.write("The average of %d and %d is %d\n" % (firstInt, secondInt, average)

The format operator "%" provides more control over how operands are
formatted.  The format string works just like C.

-- 
Grant Edwards
grante at visi.com



More information about the Python-list mailing list