def byte_size(s): print(s) # ?? # Hello World print(s.encode(‘utf-8‘)) # b‘\xf0\x9f\x98\x80‘ # b‘Hello World‘ print(len(s.encode(‘utf-8‘))) # 4 11 byte_size(‘??‘) # 4 byte_size(‘Hello World‘) # 11
原文:https://www.cnblogs.com/hany-postq473111315/p/12821692.html