循环处理序列中的值,循环处理序列,#!/usr/bin/p


#!/usr/bin/python#coding=utf-8''' 迭代序列中的值,然后进行修改 '''#method1 使用map内建函数def append(var):    return var*4for value in map(append,"apache") :print(value)#method2 使用列推导式print("split".center(20,"-"))for value in [ch*4 for ch in "apache"]:print(value)#method3 使用lambda函数print("split".center(20,"-"))for value in map(lambda x :x*4,"apache") :print(value)#method4 使用循环print("split".center(20,"-"))tempList = list()for ch in "apache":    tempList.append(ch*4)for value in tempList:    print(value)#method5 使用enumerateprint("split".center(20,"-"))stringList = list("apache")for (index ,value) in enumerate(stringList):    stringList[index] = value*4for value in stringList:    print(value)#该片段来自于http://byrx.net

评论关闭