如何在Python 3中打印出编号列表 [英] How to print out a numbered list in Python 3
本文介绍了如何在Python 3中打印出编号列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印出每个python列表的索引位置,使其从1而不是0开始.这是我希望它看起来像的一个想法:
How do I print out the index location of each of a python list so that it starts at 1, rather than 0. Here's an idea of what I want it to look like:
blob = ["a", "b", "c", "d", "e", "f"]
for i in blob:
print(???)
输出:
1 a
2 b
3 c
4 d
5 e
我需要知道的是如何将这些数字显示在我要打印的内容旁边?我可以打印出a-e没问题,但是我不知道如何为列表编号.
What I need to know is how do I get those numbers to show up alongside what I'm trying to print out? I can get a-e printed out no problem, but I can't figure out how to number the list.
推荐答案
for a, b in enumerate(blob, 1):
print '{} {}'.format(a, b)
这篇关于如何在Python 3中打印出编号列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文