Python循环处理序列中的值操作

mac2022-06-30  75

Python循环处理序列中的值操作,具体代码如下:

#!/usr/bin/python #coding=utf-8 ''' Created on 2013-6-14 迭代序列中的值,然后进行修改 @author: Administrator ''' #method1 使用map内建函数 def append(var):     return var*4 for 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)

转载于:https://www.cnblogs.com/fdtfdyh/p/3139853.html

最新回复(0)