# Revision history [back]

### Adding elements to a set

I learned Python a long while ago before I decided to get into SageMath for mathematical purposes.

I am a bit puzzled that I don't seem to have a way to add an element to a set when using the SageMath definition 'Set()', but there seems to be no problem when doing this using the Python definition 'set()', namely:

a=2; b=3; c=4
D=Set([a,b])


gives the error

'Set_object_enumerated_with_category' object has no attribute 'add'


whereas

a=2; b=3; c=4
D=set([a,b])


gives no problem (notice the difference in capital letter when creating set).

I am using the following workaround

a=2; b=3; c=4
D=Set([a,b])
D=D.union(Set([c]))


but it seems rather artificial. Is there no more natural way to proceed? Is there a natural reason to explain why 'add' is not a method of 'Set'?

 2 retagged FrédéricC 5151 ●3 ●43 ●112

### Adding elements to a set

I learned Python a long while ago before I decided to get into SageMath for mathematical purposes.

I am a bit puzzled that I don't seem to have a way to add an element to a set when using the SageMath definition 'Set()', but there seems to be no problem when doing this using the Python definition 'set()', namely:

a=2; b=3; c=4
D=Set([a,b])


gives the error

'Set_object_enumerated_with_category' object has no attribute 'add'


whereas

a=2; b=3; c=4
D=set([a,b])


gives no problem (notice the difference in capital letter when creating set).

I am using the following workaround

a=2; b=3; c=4
D=Set([a,b])
D=D.union(Set([c]))


but it seems rather artificial. Is there no more natural way to proceed? Is there a natural reason to explain why 'add' is not a method of 'Set'?

 3 retagged FrédéricC 5151 ●3 ●43 ●112

### Adding elements to a set

I learned Python a long while ago before I decided to get into SageMath for mathematical purposes.

I am a bit puzzled that I don't seem to have a way to add an element to a set when using the SageMath definition 'Set()', but there seems to be no problem when doing this using the Python definition 'set()', namely:

a=2; b=3; c=4
D=Set([a,b])


gives the error

'Set_object_enumerated_with_category' object has no attribute 'add'


whereas

a=2; b=3; c=4
D=set([a,b])

a=2; b=3; c=4