The Python Game Book

code games. learn Python.

User Tools

Site Tools


en:glossary:a:any

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:glossary:a:any [2020/05/13 10:32]
horst
en:glossary:a:any [2020/05/13 10:36]
horst
Line 4: Line 4:
  
 <blockquote>Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to: <blockquote>Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:
-<code python; gutter=false>+<code python; gutter:false>
 def any(iterable): def any(iterable):
     for element in iterable:     for element in iterable:
Line 16: Line 16:
  
 Use any() instead of an expression with a lot of ''or'' operators: Use any() instead of an expression with a lot of ''or'' operators:
 +
 +<code python;gutter:false>
 +# instead of:
 +coordinate_is_invalid = (x < 0) or (y < 0) or (x > 10) or (y >10)
 +# use any():
 +coordinate_is_invalid = any([x<0,y<0, x>10, y>10])
 +</code> 
 +</code>
  
  
en/glossary/a/any.txt ยท Last modified: 2020/05/13 10:36 by horst