Created
April 18, 2020 08:29
-
-
Save workze/ebd7eda1661159ebb05722c4f5f433c7 to your computer and use it in GitHub Desktop.
python list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = ['html', 'js', 'css', 'python'] | |
list = ['html', 'js', 'css', 'python'] | |
# 方法1 | |
print '遍历列表方法1:' | |
for i in list: | |
print ("序号:%s 值:%s" % (list.index(i) + 1, i)) | |
print '\n遍历列表方法2:' | |
# 方法2 | |
for i in range(len(list)): | |
print ("序号:%s 值:%s" % (i + 1, list[i])) | |
# 方法3 | |
print '\n遍历列表方法3:' | |
for i, val in enumerate(list): | |
print ("序号:%s 值:%s" % (i + 1, val)) | |
# 方法3 | |
print '\n遍历列表方法3 (设置遍历开始初始位置,只改变了起始序号):' | |
for i, val in enumerate(list, 2): | |
print ("序号:%s 值:%s" % (i + 1, val)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment