Key

Key[key]
represents a key used to access a value in an association.

Key[key][assoc]
extracts the value corresponding to key in the association assoc.

DetailsDetails

  • Key is used in functions such as Part to access values in Association objects.
  • Key can normally be omitted when key is a string.

ExamplesExamplesopen allclose all

Basic Examples  (4)Basic Examples  (4)

Extract a value from an association as a part:

In[1]:=
Click for copyable input
Out[1]=

Extract a value from an association by function application:

In[2]:=
Click for copyable input
Out[2]=

The Key wrapper is not necessary when the key is a string:

In[1]:=
Click for copyable input
Out[1]=

Lookups in associations interoperate with parts in lists and other expressions:

In[1]:=
Click for copyable input
Out[1]=

The explicit Key can be omitted when the keys in an association are strings:

In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=

Key is normally generated by functions such as Position:

In[1]:=
Click for copyable input
Out[1]=

Use Extract to extract the values:

In[2]:=
Click for copyable input
Out[2]=
Introduced in 2014
(10.0)