2014-01-24 15:50:40 -05:00
|
|
|
a = b"123"
|
|
|
|
print(a)
|
|
|
|
print(str(a))
|
|
|
|
print(repr(a))
|
|
|
|
print(a[0], a[2])
|
|
|
|
print(a[-1])
|
2014-03-21 17:46:59 -04:00
|
|
|
print(str(a, "utf-8"))
|
|
|
|
print(str(a, "utf-8", "ignore"))
|
|
|
|
try:
|
|
|
|
str(a, "utf-8", "ignore", "toomuch")
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
2014-01-24 15:50:40 -05:00
|
|
|
|
|
|
|
s = 0
|
|
|
|
for i in a:
|
|
|
|
s += i
|
|
|
|
print(s)
|
2014-03-21 17:46:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
print(bytes("abc", "utf-8"))
|
|
|
|
print(bytes("abc", "utf-8", "replace"))
|
|
|
|
try:
|
|
|
|
bytes("abc")
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
try:
|
|
|
|
bytes("abc", "utf-8", "replace", "toomuch")
|
|
|
|
except TypeError:
|
|
|
|
print("TypeError")
|
|
|
|
|
|
|
|
print(bytes(3))
|
|
|
|
|
|
|
|
print(bytes([3, 2, 1]))
|
|
|
|
print(bytes(range(5)))
|
|
|
|
|
2014-08-11 15:36:38 -04:00
|
|
|
# Make sure bytes are not mistreated as unicode
|
|
|
|
x = b"\xff\x8e\xfe}\xfd\x7f"
|
|
|
|
print(len(x))
|
|
|
|
print(x[0], x[1], x[2], x[3])
|