# xarray.DataArray.str.format

#### DataArray.str.format(\*args, \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L597-L680)

Perform python string formatting on each element of the DataArray.

This is equivalent to calling str.format on every element of the
DataArray. The replacement values can either be a string-like
scalar or array-like of string-like values. If array-like,
the values will be broadcast and applied elementwiseto the input
DataArray.

#### NOTE
Array-like values provided as \*args will have their
dimensions added even if those arguments are not used in any
string formatting.

#### WARNING
Array-like arguments are only applied elementwise for \*args.
For \*\*kwargs, values are used as-is.

* **Parameters:**
  * **\*args** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)) – Values for positional formatting.
    If array-like, the values are broadcast and applied elementwise.
    The dimensions will be placed at the end of the output array dimensions
    in the order they are provided.
  * **\*\*kwargs** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)) – Values for keyword-based formatting.
    These are **not** broadcast or applied elementwise.
* **Returns:**
  **formatted** (`same type as values`)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('dd89e5c6-6b6d-4a34-bae9-8194f3bedee1','f96a2bf7-13cf-4ad9-ba2a-38c6d557c4a9','18c3192c-df7c-41a3-8376-cf7b5df6a568','../lite/tree/../notebooks/index.html?path=1f3710dd_4668_432c_a3cb_0a7036360ecb.ipynb','None')">Try it in your browser!</button></div>

Create an array to format.

```pycon
>>> values = xr.DataArray(
...     ["{} is {adj0}", "{} and {} are {adj1}"],
...     dims=["X"],
... )
```

Set the values to fill.

```pycon
>>> noun0 = xr.DataArray(
...     ["spam", "egg"],
...     dims=["Y"],
... )
>>> noun1 = xr.DataArray(
...     ["lancelot", "arthur"],
...     dims=["ZZ"],
... )
>>> adj0 = "unexpected"
>>> adj1 = "like a duck"
```

Insert the values into the array

```pycon
>>> values.str.format(noun0, noun1, adj0=adj0, adj1=adj1)
<xarray.DataArray (X: 2, Y: 2, ZZ: 2)> Size: 1kB
array([[['spam is unexpected', 'spam is unexpected'],
        ['egg is unexpected', 'egg is unexpected']],

       [['spam and lancelot are like a duck',
         'spam and arthur are like a duck'],
        ['egg and lancelot are like a duck',
         'egg and arthur are like a duck']]], dtype='<U33')
Dimensions without coordinates: X, Y, ZZ
```

<div id="18c3192c-df7c-41a3-8376-cf7b5df6a568" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('dd89e5c6-6b6d-4a34-bae9-8194f3bedee1','18c3192c-df7c-41a3-8376-cf7b5df6a568')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('dd89e5c6-6b6d-4a34-bae9-8194f3bedee1','18c3192c-df7c-41a3-8376-cf7b5df6a568')">Open In Tab</button></div><div id="f96a2bf7-13cf-4ad9-ba2a-38c6d557c4a9" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`str.format`](https://docs.python.org/3/builtins/stdtypes.html#str.format)
