Text formatting error: '=' alignment not allowed in string format specifier

前端 未结 6 1422
庸人自扰
庸人自扰 2020-12-30 19:24

What does \'=\' alignment mean in the following error message, and why does this code cause it?

>&         


        
6条回答
  •  时光说笑
    2020-12-30 19:57

    In my case, I was trying to zero-pad a string instead of a number.

    The solution was simply to convert the text to a number before applying the padding:

    num_as_text = '23'
    num_as_num = int(num_as_text)
    padded_text = f'{num_as_num:03}'
    

提交回复
热议问题