Next / Previous / Contents / TCC Help System / NM Tech homepage

20.38. set(): Create an algebraic set

Use this function to create a set value. Here is the general form:

set(S)

The optional argument S is any iterable; the return value is a new set instance containing the unique values from S. When called with no arguments, this function returns a new, empty set. Examples:

>>> empty = set()
>>> empty
set([])
>>> len(empty)
0
>>> swallows=set(['African', 'European'])
>>> swallows
set(['European', 'African'])
>>> len(swallows)
2
>>> set ( (0, 0, 0, 58, 0, 0, 58, 17) )
set([0, 17, 58])

For more information about sets, see Section 15, “Types set and frozenset: Set types”.