Python2中map直接返回做用後的元素的列表函數
1 >>> a = [1,3,5,7,9] 2 >>> b = [2,4,6,8,0] 3 >>> map(lambda x, y: x+y, a, b) 4 [3, 7, 11, 15, 9] 5 >>>
Python3中map返回的則是一個map對象spa
1 >>> a = [1, 3, 5, 7, 9] 2 >>> b = [2, 4, 6, 8, 0] 3 >>> map(lambda x,y: x + y, a, b) 4 <map object at 0x7f53640e3588> 5 >>>
若是想獲得列表對象,則還須要調用list轉化爲列表對象code
1 >>> list(map(lambda x,y: x + y, a, b)) 2 [3, 7, 11, 15, 9] 3 >>>
1 >>> a = [1, 3, 5, 7, 9] 2 >>> b = [2, 4, 6, 8, 0] 3 >>> list(map(a,b)) 4 Traceback (most recent call last): 5 File "<stdin>", line 1, in <module> 6 TypeError: 'list' object is not callable 7 >>>
所以,若是map()函數的func參數不指定的話,須要使用zip(seq1, seq2[,...[,seqn)函數代替對象