Expand description
Python number and string formatting corners that show up in console
output: round(x, n), f"{x:.1f}", width padding by character count,
s[:n] slicing, and html.escape.
Functions§
- commas
f"{n:,}"— thousands separators, sign kept in front.- fixed
f"{x:.{prec}f}", spelling infinities and NaN the way Python does.- head
s[:n]— the firstncharacters.- html_
escape html.escape(s)withquote=True.- pad_
left f"{s:>width}"— pad on the left towidthcharacters.- pad_
right f"{s:<width}"— pad on the right towidthcharacters.- round_
to round(x, ndigits): correctly rounded on the binary value, ties to even — the same digits CPython’sfloat.__round__produces.