Videos
You want
for v in values: print(f'{v:<10.2} value')
Detailed rules can be found in Format String Syntax:
The general form of a standard format specifier is:
format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision][type]
For your case, you want the [align] and [.precision].
Dependent on the result you want, you can combine them normally such as;
for v in values: print(f"{v:<10.2} value")
#1.2e+01 value
#1.4e+01 value
However, your result does not seem like the result you're looking for.
To force the fixed notation of the 2 you need to add f:
for v in values: print(f"{v:<10.2f} value")
#12.11 value
#13.95 value
You can read more on format specifications here.
you should to put the format_string as variable
temp = f'{i:{format_string}}' + temp
the next code after : is not parsed as variable until you clearly indicate.
And thank @timpietzcker for the link to the docs: formatted-string-literals
You need to keep the alignment and padding tokens separate from each other:
def display_pattern(n):
padding = 4
align = ">"
temp = ''
for i in range(1, n + 1):
temp = f'{i:{align}{padding}}' + temp
print(temp)
EDIT:
I think this isn't quite correct. I've done some testing and the following works as well:
def display_pattern(n):
align = ">4"
temp = ''
for i in range(1, n + 1):
temp = f'{i:{align}}' + temp
print(temp)
So I can't really say why your method wouldn't work...