Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python string format "%4d"%

I have this code:

print("%4d"%word, end="")

Right now it's hard-coded to 4 letters words (The GUI is in the terminal)

I would like, if possible, for it to be dynamic after the biggest word chosen, is that possible and if so how?

like image 508
Benim Svensson Avatar asked Nov 08 '22 13:11

Benim Svensson


1 Answers

Using the new python formatting you could do it as follows:

print "{{0}:.{1}}".format(word, n)
like image 53
user1767754 Avatar answered Nov 15 '22 06:11

user1767754