String 使用字符串打印格式
打印结果:String 使用字符串打印格式,string,python-3.x,String,Python 3.x,打印结果: a = [('sample\\assignments.html', 'C:\\Users\\AJ\\Desktop\\sample\\sample\\projects.html', 'sample\\projects.html', False),('sample\\assignments.html','C:\\Users\\AJ\\Desktop\\sample\\sample\\docs-assets\\ico\\favicon.png', 'sample\\docs-assets
a = [('sample\\assignments.html', 'C:\\Users\\AJ\\Desktop\\sample\\sample\\projects.html', 'sample\\projects.html', False),('sample\\assignments.html','C:\\Users\\AJ\\Desktop\\sample\\sample\\docs-assets\\ico\\favicon.png', 'sample\\docs-assets\\ico\\favicon.png', False)]
print("Broken link")
print("{:>0}{:>35}".format("Source HTML","Link"))
print("============================================================")
for item in a:
b = list(item)
print("{:>0}{:>35}".format(b[0],b[2]))
有人能纠正我的代码,使第二列链接中的所有文本对齐或对齐吗
在我的程序中,a列表包含许多元组,其中b[0]和b[2]的长度不同
我真的不确定{}中的.format和空格指示符是如何工作的
谢谢我想你要做的是把这些栏目都对齐。这意味着您应该使用长度相等的空格填充所有字符串,然后根据需要添加\t或更多空格。我不确定python中是否已经有这样的东西。
Broken link
Source HTML Link
============================================================
sample\assignments.html sample\projects.html
sample\assignments.html sample\docs-assets\ico\favicon.png
sample\index.html sample\dist\css\bootstrap.css
sample\testkeys.html sample\assignments.html
sample\testkeys.html sample\index.html
print("{:<26}{}".format("Source HTML","Link"))
print("="*60)
for item in a:
b = list(item)
print("{:<26}{}".format(b[0],b[2]))
Broken link
Source HTML Link
============================================================
sample\assignments.html sample\projects.html
sample\assignments.html sample\docs-assets\ico\favicon.png