python - 如何修改此代码以用于多个列表?

标签 python python-3.x

我有这段代码可以将两个列表转换为垂直列并打印出来:

team1 = ['Vàlentine', 'Consus', 'Never Casual ', 'NucIear', 'Daltwon']
team2 = ['The Aviator', 'Iley', 'Nisquick', 'Dragoon', 'WAACK']

for t1, t2 in zip(team1, team2):
    print('%-20s %s' % (t1, t2))

如何调整此代码以添加第三个列表,例如 team3 = ['...']

输出:

Vàlentine            The Aviator       <team3 here>
Consus               Iley
Never Casual         Nisquick
NucIear              Dragoon
Daltwon              WAACK

使用:

for t1, t2, t3 in zip(team1, team2, team3):
    print('%-20s %s' % str(t1, t2, t3))

好像不行。

最佳答案

像这样

team1 = ['Vàlentine', 'Consus', 'Never Casual ', 'NucIear', 'Daltwon']
team2 = ['The Aviator', 'Iley', 'Nisquick', 'Dragoon', 'WAACK']
team3 = ['Ronaldo', 'Messi', 'Zidane', 'Me', 'Raul']
for t1, t2, t3 in zip(team1, team2, team3):
    print('%-20s %-20s %s' % (t1, t2, t3))

关于python - 如何修改此代码以用于多个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57173818/

相关文章:

python-3.x - aiohttp异步请求的任务异常

python - 使用python和mysql时,SQL语句中并未使用所有参数

python - Python 中的索引错误 : "string index out of range"

python - matplotlib,占用两个图空间的子图

Python - 随机森林 - 迭代添加树

python - Flask-WTForms 更改提交的日期字段值

python - 具有 Mysql 坐标/多边形精度的 Geodjango

Python:如何使用 BeautifulSoup 从 HTML 页面中提取 URL?

python-3.x - 我可以在 python3 中格式化文档字符串吗

Python无法安装包