Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 使用字符串打印格式_String_Python 3.x - Fatal编程技术网

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