传递给文档的格式化问题。下面的示例companyList在每次运行脚本时都会有所不同
companyList = ["Apple - Seattle Washington (800) 555-5555", "Microsoft - Tampa Florida (800) 555-1234", "Samsung - Tokyo Japan (01) 555 123-1234"]
现在,格式化此文本的代码行是:
companyInfo = "\n\n".join(companyList)
和companyInfo输出如下:
Apple - Seattle Washington (800) 555-5555 Microsoft - Tampa Florida (800) 555-1234 Samsung - Tokyo Japan (01) 555 123-1234
如何将其重写为这样的格式(注意每个新行标注一个):
Apple - Seattle Washington (800) 555-5555
Microsoft - Tampa Florida (800) 555-1234
Samsung - Tokyo Japan (01) 555 123-1234
非常感谢提前
答案 0 :(得分:1)
你可以这样做:
companyInfo = "\n\n".join("\t%s" % x for x in companyList)