code: def to_bytes(s, encoding=None, errors='strict'):
      
      encoding = encoding or 'utf-8'
  
      if is_unicode(s):
          return s.encode(encoding, errors)
      elif is_strlike(s):
          return s
      else:
          if six.PY2:
              return str(s)
          else:
              return str(s).encode(encoding, errors)
docs: Convert string to bytes.