title: Check if a byte string ends with a special character with Python
body: <p>I am parsing a XML file which contains some UTF-8 encoded text with <strong>Python 3.6</strong>:</p>
  
  <pre><code>&lt;line&gt;
    &lt;text&gt;Some text which could end with ¬&lt;/text&gt;
  &lt;/line&gt;
  </code></pre>
  
  <p>I am parsing it with <code>xml.etree.ElementTree</code> and I get the <code>text</code> element as an element:</p>
  
  <pre><code>&lt;Element 'text' at 0x105577c78&gt;
  </code></pre>
  
  <p>I can get the text string with</p>
  
  <pre><code>text_string = text.text.encode('utf-8')
  msg = "Text string: {}".format(text_string)
  self.stdout.write(self.style.SUCCESS(msg))
  </code></pre>
  
  <p>And I get:</p>
  
  <pre><code>Text string: b'Some text which could end with \xac'
  </code></pre>
  
  <p>Now I need to know if this string is ending with the <strong>¬</strong> character:</p>
  
  <pre><code>if text_string.endswith('¬'):
      print("The text ends which the char!")
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>TypeError: endswith first arg must be bytes or a tuple of bytes, not str
  </code></pre>
  
  <p>If I change to <code>if text_string.endswith(b'¬'):</code> I get another error:</p>
  
  <pre><code>    if text_string.endswith(b'\xac'):
                             ^
  SyntaxError: bytes can only contain ASCII literal characters.
  </code></pre>
  
  <p>I understand I am confused because <code>text_string</code> is bytes and not string, but I cannot understand how I can solve my problem.</p>
  
  <p>How I can convert bytes to string?
  Or how I can search for a special character into a byte object?</p>
  
  <p>Thanks!</p>