字节,字节数组,字符串,布尔类型转换,ACSII

# 字符转成字节
bytes1 = bytes('你好啊', encoding='utf-8')
print(bytes1) # b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x95\x8a'

# 字节转成字符
string1 = str(bytes1, encoding='utf-8')
print(string1) # 你好啊

# 字符转成字节数组
byteArray1 = bytearray('你好啊', encoding='utf-8')
print(byteArray1) # bytearray(b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x95\x8a')

# 字节数组转成字符
string2 = str(byteArray1, encoding='utf-8')
print(string2) # 你好啊

# bool类型转换
# return False
print(bool({}))
print(bool(()))
print(bool(("")))
print(bool([]))
print(bool(""))
print(bool(None))

# return True
print(bool(" "))
print(bool({"":""}))
print(bool([""]))

# ASCII
print(chr(32)) # 空格
print(chr(48)) # 0
print(chr(57)) # 9
print(chr(65)) # A
print(chr(90)) # Z
print(chr(97)) # a
print(chr(122)) # z

print(ord(' ')) # 32
print(ord('A')) # 65
posted on 2018-01-15 20:56  jovelove  阅读(474)  评论(0编辑  收藏  举报