mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
Added devilish [False] example to show that lists in a boolean context are only based on length [thanks A.H.]
This commit is contained in:
@@ -315,9 +315,12 @@ ValueError: list.index(x): x not in list</samp></pre>
|
||||
<samp>no, it's false</samp>
|
||||
<a><samp class=p>>>> </samp><kbd>is_it_true(['a'])</kbd> <span>③</span></a>
|
||||
<samp>yes, it's true</samp></pre>
|
||||
<a><samp class=p>>>> </samp><kbd>is_it_true([False])</kbd> <span>④</span></a>
|
||||
<samp>yes, it's true</samp></pre>
|
||||
<ol>
|
||||
<li>In a boolean context, an empty list is false.
|
||||
<li>Any list with at least one item is true.
|
||||
<li>Any list with at least one item is true. The value of the items is irrelevant.
|
||||
</ol>
|
||||
<!--
|
||||
<h2 id=sets>Sets</h2>
|
||||
|
||||
Reference in New Issue
Block a user