title: Python strings and str() method encoding and decoding
body: <p>I see that <a href="http://docs.python.org/2/library/stdtypes.html#string-methods" rel="nofollow noreferrer">the Python manual</a> mentions <code>.encode()</code> and <code>.decode()</code> string methods. Playing around on the Python CLI I see that I can create unicode strings <code>u'hello'</code> with a different datatype than a 'regular' string <code>'hello'</code> and can convert / cast with <code>str()</code>. But the real problems start when using characters above ASCII 127 <code>u'שלום'</code> and I am having a hard time determining empirically exactly what is happening.</p>
  
  <p><a href="https://stackoverflow.com/questions/1207457/convert-unicode-to-string-in-python-containing-extra-symbols">Stack Overflow</a> <a href="https://stackoverflow.com/questions/2513027/encoding-gives-ascii-codec-cant-encode-character-ordinal-not-in-range128">is</a> <a href="https://stackoverflow.com/questions/17026845/why-is-python-insisting-on-using-ascii">overflowing</a> <a href="https://stackoverflow.com/questions/2365411/python-convert-unicode-to-ascii-without-errors">with</a> <a href="https://stackoverflow.com/questions/6539881/python-converting-from-iso-8859-1-latin1-to-utf-8">examples</a> <a href="https://stackoverflow.com/questions/3224268/python-unicode-encode-error">of</a> <a href="https://stackoverflow.com/questions/2239017/how-do-i-properly-work-with-unicode-characters-in-python-to-keep-from-getting-er">confusion</a> <a href="https://stackoverflow.com/questions/7634715/python-decoding-unicode-is-not-supported">regarding</a> <a href="https://stackoverflow.com/questions/8436522/noob-queries-on-unicode-and-str-methods-in-python">Python's</a> <a href="https://stackoverflow.com/questions/2596714/why-does-python-print-unicode-characters-when-the-default-encoding-is-ascii">unicode</a> <a href="https://stackoverflow.com/questions/985486/utf-8-problem-in-python-when-reading-chars">and</a> <a href="https://stackoverflow.com/questions/6504200/how-to-decode-unicode-raw-literals-to-readable-string">string-encoding/decoding</a> <a href="https://stackoverflow.com/questions/196345/how-to-check-if-a-string-in-python-is-in-ascii">handling</a>.</p>
  
  <p><strong>What exactly happens (how are the bytes changed, and how is the datatype changed) when encoding and decoding strings with the <code>str()</code> method, especially when characters that cannot be represented in 7 bytes are included in the string?</strong> Is it true, as it seems, that a Python variable with datatype <code>&lt;type 'str'&gt;</code> can be both encoded and decoded? If it is encoded, I understand that means that the string is represented by UTF-8, ISO-8859-1, or some other encoding, is this correct? If it is decoded, what does this mean? Are decoded strings unicode? If so, then why don't they have the datatype <code>&lt;type 'unicode'&gt;</code>?</p>
  
  <p>In the interest of those who will read this later, I think that both Python 2 and Python 3 should be addressed. Thank you!</p>