set_9 = {1,2,3,4,5}
for a in set_9:
print(f"{a:>6.2f}")
Output
1.00
2.00
3.00
4.00
5.00
Is :>
an operator? If not, what type is it?
What is 6.2f
mean?
The format used is called Formatted string literals or f-strings, which is f"{a:>6.2f}"
Anything inside the curly braces is replacement field, which is {a:>6.2f}
Here, a
is the field_name and >6.2f
is the format_spec.
replacement_field::= "{" [field_name] [":" conversion] [":" format_spec] "}"
Expanding the format specification used in your example:
> - align - Right align the field
6 - width - Minimum width (by default space is used as fill character)
.2 - precision - Number of digits after the decimal point
f - type - Floating point notation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.