python str与bytes之间的转换

it2025-10-07  1

python str与bytes之间的转换

 

# bytes objectb = b"example"

# str objects = "example"

# str to bytessb = bytes(s, encoding = "utf8")

# bytes to strbs = str(b, encoding = "utf8")

# an alternative method # str to bytessb2 = str.encode(s)

# bytes to strbs2 = bytes.decode(b)

最新回复(0)