python map函数怎么用啊!

下面是我的代码:>>>def cube(x):return x*x*x

>>>map (cube,range(1,11))
可是结果却是: <map object at 0x01397210>
而不是预想中的 [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
这是怎么回事啊

1、对可迭代函数'iterable'中的每一个元素应用‘function’方法,将结果作为list返回。
来个例子:
>>> def add100(x):
... return x+100
...
>>> hh = [11,22,33]
>>> map(add100,hh)
[111, 122, 133]
就像文档中说的:对hh中的元素做了add100,返回了结果的list。

2、如果给出了额外的可迭代参数,则对每个可迭代参数中的元素‘并行’的应用‘function’。(翻译的不好,这里的关键是‘并行’)
>>> def abc(a, b, c):
... return a*10000 + b*100 + c
...
>>> list1 = [11,22,33]
>>> list2 = [44,55,66]
>>> list3 = [77,88,99]
>>> map(abc,list1,list2,list3)
[114477, 225588, 336699]
看到并行的效果了吧!在每个list中,取出了下标相同的元素,执行了abc()。

3、如果'function'给出的是‘None’,自动假定一个‘identity’函数(这个‘identity’不知道怎么解释,看例子吧)
>>> list1 = [11,22,33]
>>> map(None,list1)
[11, 22, 33]
>>> list1 = [11,22,33]
>>> list2 = [44,55,66]
>>> list3 = [77,88,99]
>>> map(None,list1,list2,list3)
[(11, 44, 77), (22, 55, 88), (33, 66, 99)]
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-15
我这里测试你的代码是可行的 结果都正确
你关闭python 之后 重新在写一次看看 估计你先前修改了什么地方 所以出错了
要不就是语法上的问题 python2.*的版本跟3.0以上的语法有些不同
第2个回答  推荐于2017-10-05
list(map(cube,range(1,11)))

python 3以上要加list本回答被提问者采纳