What does fmt="{:>3} mean?

Asked 2 years ago, Updated 2 years ago, 40 views

fmt="{:>3}"

Please tell me what this code means.
What is substituted for fmt?
Thank you for your cooperation.

python python3

2022-09-30 17:55

1 Answers

Probably a format string for the format function.
It's a little different from the example on the page below, but I think it represents a three-digit right-fill specification.

fmt is not something that has been converted or applied, but only the {:>3} itself of the specified string.

Formatted Mini-Language Specifications

> Force right-filling in available space (default for some objects).

Width - [Introduction to Python] How to write strings with the format function

>Take any width and fill it right

string1 = 'Left Packed'
string2 = 'Centralized'
string3 = 'Right-filling'

print('{{0:<10}'.format(string1)))
print('{0:^10}'.format(string2))
print('{{0:>10}'.format(string3))

Run Results

Left Packing       
   centralization   
       right-hand packing

If you apply the above, it will look like this.

fmt="{:>3}"

string1 = 'X'

print(fmt.format(string1))

  X
# Two-digit spaces followed by `X` are displayed


2022-09-30 17:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.