Dalla documentazione di Python 3 ( lo stesso vale per Python 2.7 ):
Le parentesi graffe o la funzione set () possono essere utilizzate per creare set. Nota: per creare un set vuoto devi usare set (), non {}; quest'ultimo crea un dizionario vuoto, una struttura dati che discuteremo nella prossima sezione.
in Python 2.7:
>>> my_set = {'foo', 'bar', 'baz', 'baz', 'foo'}
>>> my_set
set(['bar', 'foo', 'baz'])
Tieni presente che {}viene utilizzato anche per map/ dict:
>>> m = {'a':2,3:'d'}
>>> m[3]
'd'
>>> m={}
>>> type(m)
<type 'dict'>
Si può anche usare una sintassi completa per inizializzare i set:
>>> a = {x for x in """didn't know about {} and sets """ if x not in 'set' }
>>> a
set(['a', ' ', 'b', 'd', "'", 'i', 'k', 'o', 'n', 'u', 'w', '{', '}'])