⬅︎ Back to How to pad/fill a string by a variable in Python using f-strings
Hi, at least it works with a different single char instead of a whitespace...>>> mystr = "hello">>> f'{mystr:<10}''hello '>>> f'{mystr:X<10}''helloXXXXX'>>> foo = 'XYZ'>>> f'{mystr:{foo}<10}'Traceback (most recent call last): File "<stdin>", line 1, in <module>ValueError: Invalid format specifier
Comment
Hi, at least it works with a different single char instead of a whitespace...
>>> mystr = "hello"
>>> f'{mystr:<10}'
'hello '
>>> f'{mystr:X<10}'
'helloXXXXX'
>>> foo = 'XYZ'
>>> f'{mystr:{foo}<10}'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier