example-code-2e/strings-bytes/strings-bytes-test.txt
2014-10-14 14:26:55 -03:00

23 lines
414 B
Plaintext

>>> s = 'naïve' <1>
>>> b = b'naïve' <2>
Traceback (most recent call last):
...
SyntaxError: bytes can only contain ASCII literal characters.
>>> b = bytes('naïve', 'iso8859-1') <3>
>>> b <4>
b'na\xefve'
>>> s <5>
'naïve'
>>> b == s.encode('iso8859-1') <6>
True
>>> s[2] <7>
'ï'
>>> b[2] <8>
239
>>> ord(s[2]) <9>
239
>>> s.upper() <10>
'NAÏVE'
>>> b.upper() <11>
b'NA\xefVE'