({{, (RefLink[SetAttributes, paclet:ref/SetAttributes])[s,attr]
adds attr to the list of attributes of the symbol s. }})

OpenersNotesSection(Spacer1)Details

(RefLink[SetAttributes, paclet:ref/SetAttributes]) modifies (RefLink[Attributes, paclet:ref/Attributes])[s].

(RefLink[SetAttributes, paclet:ref/SetAttributes])[s,{(Subscript[attr, 1]),(Subscript[attr, 2]),…}] sets several attributes at a time.

(RefLink[SetAttributes, paclet:ref/SetAttributes])[{(Subscript[s, 1]),(Subscript[s, 2]),…},attrs] sets attributes of several symbols at a time.

(RefLink[SetAttributes, paclet:ref/SetAttributes]) has the attribute (RefLink[HoldFirst, paclet:ref/HoldFirst]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (12)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

SetAttributes[f,HoldAll]

f[1+2]

SetAttributes[plus,{Flat,Orderless}]

plus[a,plus[c,b]]

OpenersExampleSection1(Spacer1)Scope  (3)

Add an attribute to the list of attributes of a symbol:

SetAttributes[f,Flat]

Add more attributes; the previous ones are retained:

SetAttributes[f,Orderless]

Attributes[f]

Add several attributes:

SetAttributes[f,{HoldAll,Protected}]

Add the same attributes to several symbols:

SetAttributes[{f,g,h},{HoldFirst,NHoldFirst}]

OpenersExampleSection2(Spacer1)Properties & Relations  (6)

Set a single attribute for the symbols f and g:

Attributes[f]=Listable;
Attributes[g]=Listable;

(RefLink[SetAttributes, paclet:ref/SetAttributes]) adds to the already existing attributes; (RefLink[Attributes, paclet:ref/Attributes])[g]={..} resets the list:

SetAttributes[f,HoldAll];
Attributes[g]=HoldAll;

Attributes[{f,g}]

(RefLink[SetAttributes, paclet:ref/SetAttributes]) is equivalent to this assignment to the attributes:

Attributes[f]=Union[Attributes[f],{HoldFirst,NHoldFirst}]

Use (RefLink[ClearAttributes, paclet:ref/ClearAttributes]) to clear a particular attribute:

SetAttributes[f,{Flat,Orderless,OneIdentity}]

ClearAttributes[f,OneIdentity]

Attributes[f]

Protecting a symbol is equivalent to setting the (RefLink[Protected, paclet:ref/Protected]) attribute:

Protect[f];
SetAttributes[g,Protected];

Attributes[{f,g}]

You can still change the attributes of a protected symbol:

ClearAttributes[f,Protected];
Unprotect[g];

After setting the attribute (RefLink[Locked, paclet:ref/Locked]), no more changes to the attributes can be made:

SetAttributes[f,{Locked,Protected}]

A locked symbol can no longer be unprotected, as the (RefLink[Protected, paclet:ref/Protected]) attribute cannot be cleared:

Unprotect[f]

(RefLink[SetAttributes, paclet:ref/SetAttributes]) has the attribute (RefLink[HoldFirst, paclet:ref/HoldFirst]):

Attributes[SetAttributes]

syms={f,g,h};

This sets attributes of the symbol syms itself:

SetAttributes[syms,Protected]

Attributes[syms]

This sets the attributes of all symbols in the list syms:

SetAttributes[Evaluate[syms],Protected]

Attributes[{f,g,h}]

OpenersExampleSection3(Spacer1)Neat Examples  (1)

The 10 system symbols with the most attributes:

TableForm[Take[Sort[{#,Attributes[#]}&/@Names["System`*"],Length[#1[[2]]]>Length[#2[[2]]]&],10],TableDepth->2]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Attributes, paclet:ref/Attributes])  ▪  (RefLink[ClearAttributes, paclet:ref/ClearAttributes])  ▪  (RefLink[Protect, paclet:ref/Protect])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Flat and Orderless Functions, paclet:tutorial/FlatAndOrderlessFunctions])}, {▪(RefLinkPlain[Attributes, paclet:tutorial/Attributes])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Attributes, paclet:guide/Attributes])}})}})