Message262108
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. |
|
Date |
User |
Action |
Args |
2016-03-21 09:00:55 | vstinner | set | recipients:
+ vstinner, eric.smith, docs@python, serhiy.storchaka, wolma, Manvi B |
2016-03-21 09:00:55 | vstinner | set | messageid: <1458550855.3.0.364320158397.issue26506@psf.upfronthosting.co.za> |
2016-03-21 09:00:55 | vstinner | link | issue26506 messages |
2016-03-21 09:00:55 | vstinner | create | |
|