docs: def encode(string, encoding=None, errors=None):
      """Encode to specified encoding.
  
      ``encoding`` defaults to the preferred encoding.
      ``errors`` defaults to the preferred error handler.
      """
      if encoding is None:
          encoding = getpreferredencoding()
      if errors is None:
          errors = getpreferrederrors()
      return string.encode(encoding, errors)