Python for Visual Basic or C# programmers

Metalone jcb at iteris.com
Thu Jun 1 15:01:43 EDT 2006


Slight correction.
" %d" % 123 is not quite equivalent to str(123) as it does not handle
negative numbers the same way.
I am not sure there is a simple direct equivalent.
"%+d" % 123 --> "+123" always gives a sign.
"%4d" % 123 --> " 123"
"%4d" % -123 --> "-123"  so this works if you you know how wide the
number is.

This might be a little too tricky.
[" %d", "%d][n < 0] % n  --> selects list[0] or list[1] based upon sign
of number




More information about the Python-list mailing list