Question about output...

Mark McEahern marklists at mceahern.com
Wed Oct 16 22:37:54 EDT 2002


[Tony Warmath]
> I'm trying to produce the Python equivalent of this statement in C++:
>
> cout << "The average of " << firstInt << " and " << secondInt << " is " <<
> average << endl;

print "The average of %d and %d is %d" % (firstInt, secondInt, average)

That's called string formatting.  (Use %f if you expect a float.)

You could also do:

print "The average of ", firstInt, " and ", secondInt, " is ", average

Or replace the commas with a plus sign.

I'll let you discover further details yourself.

Cheers,

// m

-





More information about the Python-list mailing list