【发布时间】:2021-04-25 02:37:46
【问题描述】:
到目前为止,我已经得到了这个,我在让输出打印右对齐时遇到了问题。
我尝试使用.rjust 让我的输出显示如下:
abc
de
fghijklmn
但它显示如下:
abc
de
fghijklmn
这是我迄今为止尝试过的:
strings = ['abc', 'de', 'fghijklmn']
col_umn = ("\n".join(strings))
rcol_umn = (col_umn.rjust(max(len(ele) for ele in strings)))
width = max(len(ele) for ele in strings)
fillchar = " "
print(col_umn.rjust(5, fillchar))
length = max(strings)
res = max(len(ele) for ele in strings)
print(" ")
print(str(res))
【问题讨论】:
-
您需要证明每个单独的字符串,而不是所有连接在一起的字符串。
标签: python python-3.x