pythonのforループでrange、len、enumerate関数を使用する操作例
1272 ワード
#coding=utf8
print '''
Python for shell foreach 。
Python for , 。
Python print 。
print (,) 。
print , 。
'''
fruits=["apple","orange","pear","banana","peach","watermelon"]
print "I like eating some fruits,such as:",
for fruit in fruits:
print fruit,
#
#print
print '''
python range : 。
。
'''
rangeList=range(5)
print "the list of range(5) is:",rangeList
for item in rangeList:
print " element of rangList:",item
print
# for ,
string="ewang"
for char in string:
print "the char of string:",char
print '''
range() len() 。
。
'''
for index in range(len(string)):
print "the char and index of string:",string[index],"(%d)" %index
print '''
python enumerate 。
enumerate : 、
'''
for index,char in enumerate(string):
print "the char and index of string by enumerate function:",char,"(%d)" %index