This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Manvi B, docs@python, eric.smith, serhiy.storchaka, vstinner, wolma
Date 2016-03-21.09:00:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458550855.3.0.364320158397.issue26506@psf.upfronthosting.co.za>
In-reply-to
Content
Serhiy Storchaka:
> The documentation for hex() doesn't look the bests place for examples of using string formatting. I think it is enough to add short references to corresponding formatting codes.

I like Manvi B's patch with many examples. It's hard to read formatting strings, it's hard to compute the result, so full examples are just more obvious.

I don't think that it hurts to add many formatting examples. I expect that most users will combine the result of bin/hex/oct with another string, so suggesting using formatting functions will probably help them to simplify the code.

For example,
   print("x=", hex(x), "y=", hex(y))
can be written:
   print("x=%#x y=%#x" % (x, y))
or
   print("x={:#x} y={:#x}".format(x, y))
or
   print(f"x={x:#x} y={y:#x}")

The first expression using hex() adds spaces after "=", but well, it's just to give a simple example. IMHO formatting strings are more readable.
History
Date User Action Args
2016-03-21 09:00:55vstinnersetrecipients: + vstinner, eric.smith, docs@python, serhiy.storchaka, wolma, Manvi B
2016-03-21 09:00:55vstinnersetmessageid: <1458550855.3.0.364320158397.issue26506@psf.upfronthosting.co.za>
2016-03-21 09:00:55vstinnerlinkissue26506 messages
2016-03-21 09:00:55vstinnercreate