Is there a map without result in python?

前端 未结 15 1075
北恋
北恋 2020-12-03 04:33

Sometimes, I just want to execute a function for a list of entries -- eg.:

for x in wowList:
   installWow(x, \'installed by me\')

Sometime

15条回答
  •  醉梦人生
    2020-12-03 05:23

    Every expression evaluates to something, so you always get a result, whichever way you do it. And any such returned object (just like your list) will get thrown away afterwards because there's no reference to it anymore.

    To clarify: Very few things in python are statements that don't return anything. Even a function call like

    doSomething()
    

    still returns a value, even if it gets discarded right away. There is no such thing as Pascal's function / procedure distinction in python.

提交回复
热议问题