Python 3 Map function is not Calling up function

前端 未结 3 849
南旧
南旧 2020-12-03 06:49

Why doesn\'t following code print anything:

#!/usr/bin/python3
class test:
    def do_someting(self,value):
        print(value)
        return value

    de         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 07:52

    Before Python 3, map() returned a list, not an iterator. So your example would work in Python 2.7.

    list() creates a new list by iterating over its argument. ( list() is NOT JUST a type conversion from say tuple to list. So list(list((1,2))) returns [1,2]. ) So list(map(...)) is backwards compatible with Python 2.7.

提交回复
热议问题