String
# Unicode string
print('hello, 世界')
print('\u4e2d\u6587')
# Char -> Code point
ord('中')
# Code point -> Char
chr(65)
# Bytes
print(b'hello')
# String -> Bytes
'hello'.encode('utf-8')
# Bytes -> String
b'hello'.decode('utf-8')
# String length
len('中文') # 2
# String bytes
len('中文'.encode('utf-8')) # 6
String format
print('%s, %d, %f, %x' % ('hello, world', 2333, 3.14, 16))
网友评论