Python@TW: 會眾| IRC| Planet| 郵件列表| 聯絡我們
修訂版 4 和 5 的差異如下:
2007-12-30 17:12:21 修訂第 4 版
大小: 913
編輯者: keitheis
說明: add a reference
2009-04-01 04:14:22 修訂第 5 版
大小: 919
編輯者: localhost
說明: converted to 1.6 markup
這個顏色代表刪除的 這個顏色代表增加的
行號 22: 行號 22:
[http://amix.dk/blog/viewEntry/19303 amix.dk - Python 2.5: Using any function] [[http://amix.dk/blog/viewEntry/19303|amix.dk - Python 2.5: Using any function]]
行號 24: 行號 24:
[http://www.artima.com/weblogs/viewpost.jsp?thread=98196 The fate of reduce() in Python 3000] [[http://www.artima.com/weblogs/viewpost.jsp?thread=98196|The fate of reduce() in Python 3000]]
行號 26: 行號 26:
[http://docs.python.org/whatsnew/other-lang.html Other Language Changes] in Python 2.5 [[http://docs.python.org/whatsnew/other-lang.html|Other Language Changes]] in Python 2.5

自 Python 2.5 以後,內建 all() 與 any() 可用來判別选代子是否存有任何值為真或假。

以碼演義:

   1 >>> GoodSoulsComeToRest = ['Strangefolk', ('Monkey', 'Happyfolk') ]
   2 >>> all( GoodSoulsComeToRest )
   3 True
   4 >>> GoodSoulsComeToRest = [ 0, ('Monkey', 'as 0 appear in here...') ]
   5 >>> all( GoodSoulsComeToRest )
   6 False
   7 >>> any( GoodSoulsComeToRest )           # Monkey strings still there
   8 True
   9 >>> black = 0,0,0,0,0,0
  10 >>> ManInBlack = [man for man in black]  # Just a 0-list clone
  11 >>> any( ManInBlack )
  12 False
  13 >>> all( ManInBlack )                    # Since no any, of course not all
  14 False

amix.dk - Python 2.5: Using any function

The fate of reduce() in Python 3000

Other Language Changes in Python 2.5

Python/Cookbook/All&Any (上次是 localhost 在 2009-04-01 04:14:22 編輯的)