From 33e6e053bac3f138aaacaeca652cded79845f0a4 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 16 Jul 2009 09:09:13 -0400 Subject: [PATCH] explain empty sets --- native-datatypes.html | 2 +- porting-code-to-python-3-with-2to3.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native-datatypes.html b/native-datatypes.html index 3f8cf55..044e74c 100755 --- a/native-datatypes.html +++ b/native-datatypes.html @@ -478,7 +478,7 @@ IndexError: pop from empty list
  • The original list is unchanged. -

    Don’t have any values yet? Not a problem. You can create an empty set. +

    Don’t have any values yet? Not a problem. You can create an empty set.

     >>> a_set = set()    
    diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html
    index 7095d1d..19bba43 100644
    --- a/porting-code-to-python-3-with-2to3.html
    +++ b/porting-code-to-python-3-with-2to3.html
    @@ -1260,7 +1260,7 @@ except:
     
     

    set() literals (explicit)

    -

    In Python 2, the only way to define a literal set in your code was to call set(a_sequence). This still works in Python 3, but a clearer way of doing it is to use the new set literal notation: curly braces. (Dictionaries are also defined with curly braces, which makes sense once you think about it, because dictionaries are just sets of key-value pairs.) +

    In Python 2, the only way to define a literal set in your code was to call set(a_sequence). This still works in Python 3, but a clearer way of doing it is to use the new set literal notation: curly braces. This works for everything except empty sets, because dictionaries also use curly braces, so {} is an empty dictionary, not an empty set.

    The 2to3 script will not fix set() literals by default. To enable this fix, specify -f set_literal on the command line when you call 2to3.