Where am I messing up with output formatting?

前端 未结 1 848
萌比男神i
萌比男神i 2021-01-27 23:50

So I got an error message when I tried to run my code and I can\'t figure out what exactly the problem is. It says it\'s a ValueError but I can\'t figure out which one exactly.

相关标签:
1条回答
  • 2021-01-28 00:28

    You can't switch back and forth between automatic field numbering - what you get by specifying a simple {} - and manual field specification, e.g. {0}. If you want the same field repeated several times, as 'Word' is in your example, you'll have to also specify what you want the other fields to be. For example, you might want to start with the first argument, 'Word', which is element 0, and the fifth argument, '='*51, as the last, which is element 4:

    >>> print("{0}{0:27}{0:39}{0:51}\n{4}".format("Word", "Occurence", "Avg. Score", "Std. Dev.", "="*51))
    WordWord                       Word                                   Word
    
    ===================================================
    

    You'll have to decide for yourself which arguments you want to be placed where in the format string.

    0 讨论(0)
提交回复
热议问题