From 9621e1e7901b7b0a993950ededfb2ac068e8aad4 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 23 Sep 2009 08:48:48 -0400 Subject: [PATCH] clarify has_key notes --- porting-code-to-python-3-with-2to3.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index a8c676f..a304269 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -175,10 +175,10 @@ h3:before{counter-increment:h3;content:'A.' counter(h2) '.' counter(h3) '. '}
  1. The simplest form. -
  2. The or operator takes precedence over the in operator, so there is no need for parentheses here. -
  3. On the other hand, you do need parentheses here, for the same reason — or takes precedence over in. (Note: this code is completely different from the previous line. Python interprets x or y first, which results in either x (if x is true in a boolean context) or y. Then it takes that singular value and checks whether it is a key in a_dictionary.) -
  4. The in operator takes precedence over the + operator, so this form technically doesn’t need parentheses, but 2to3 includes them anyway. -
  5. This form definitely needs parentheses, since the in operator takes precedence over the + operator. +
  6. The or operator takes precedence over the in operator, so there is no need for parentheses around (x in a_dictionary) or (y in a_dictionary). +
  7. On the other hand, you do need parentheses around (x or y) here, for the same reason — or takes precedence over in. (Note: this code is completely different from the previous line. Python interprets x or y first, which results in either x (if x is true in a boolean context) or y. Then it takes that singular value and checks whether it is a key in a_dictionary.) +
  8. The in operator takes precedence over the + operator, so this form technically doesn’t need parentheses around (x + y), but 2to3 includes them anyway. +
  9. This form definitely needs parentheses around (y in a_dictionary), since the in operator takes precedence over the + operator.

Dictionary methods that return lists