You are viewing a single comment's thread from:

RE: Python Libraries: Simple... Display your Splinterlands DEC

in STEMGeeks2 years ago

This is something I am struggling with.., given a variable name.. it works.. but suffixing the :20 to a literal string.. does not. I have tried several combinations.. which either gives me errors.. or prints the 20!

print(f'Account{:20} DEC Total')

Any ideas?

Sort:  

Try this. The part you are formatting has to be in {}. It can even be an expression. Anything outside the {} is output as-is.

print(f'{"Account":20} DEC Total')

Perfect and now working.. thanks!. So quotes can go inside the squiggles and are not interpreted as variable data if enclosed with quotes.. interesting. I couldn't find a single example of this on the net.

It can be expressions like this. Probably other ways to do it. Just need to use different quotes in the {} to those around the whole string.

for n in range(20,0,-1):
    print(f'{"*"*n:20} bottles of beer')