Skip to content

Commit

Permalink
DOC: Add string formatting information to unit tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
alakocy-pec committed Jul 15, 2023
1 parent 9fc837e commit c8daf89
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tutorials/unit_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@
# operation can be performed:
print(3 * units.inch + 5 * units.cm)

#########################################################################
# ``pint`` by default will print full unit names for :class:`~pint.Quantity`.
print(f'{20 * units.meter ** 2}')

#########################################################################
# This can be reduced to symbolic by specifying a compact (~) formatter:
print(f'{20 * units.meter ** 2:~}')

#########################################################################
# A compact (~), pretty (P) formatter:
print(f'{20 * units.meter ** 2:~P}')

#########################################################################
# Place formatters following other print specifications:
print(f'{20 * units.meter ** 2:0.3f~P}')

#########################################################################
# Other string formatting options are available, see the `Pint string formatting specification
# <https://pint.readthedocs.io/en/stable/user/formatting.html>`_.

#########################################################################
# Converting Units
# ----------------
Expand Down

0 comments on commit c8daf89

Please sign in to comment.