# xarray.core.accessor_str.StringAccessor.encode

#### StringAccessor.encode(encoding, errors='strict')[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/accessor_str.py#L2888-L2912)

Encode character string in the array using indicated encoding.

* **Parameters:**
  * **encoding** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The encoding to use.
    Please see the Python documentation [codecs standard encoders](https://docs.python.org/3/library/codecs.html#standard-encodings)
    section for a list of encodings handlers.
  * **errors** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *default*: `"strict"`) – The handler for encoding errors.
    Please see the Python documentation [codecs error handlers](https://docs.python.org/3/library/codecs.html#error-handlers)
    for a list of error handlers.
* **Returns:**
  **encoded** (`same type as values`)
