# xarray.core.accessor_str.StringAccessor.format

#### StringAccessor.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('e81a5aeb-f691-4bd7-8cfe-97e7542f02b3','201bd39f-2426-4013-b8d8-5bd5835dd27b','a9c04889-56cd-4b8b-b0ee-38fb66d81a58','../lite/tree/../notebooks/index.html?path=3cd50691_5df8_4bfa_a8c3_37f1927f579b.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="a9c04889-56cd-4b8b-b0ee-38fb66d81a58" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e81a5aeb-f691-4bd7-8cfe-97e7542f02b3','a9c04889-56cd-4b8b-b0ee-38fb66d81a58')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e81a5aeb-f691-4bd7-8cfe-97e7542f02b3','a9c04889-56cd-4b8b-b0ee-38fb66d81a58')">Open In Tab</button></div><div id="201bd39f-2426-4013-b8d8-5bd5835dd27b" 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)
