美文网首页
3. String & Unicode

3. String & Unicode

作者: 捕鲸小能手 | 来源:发表于2016-10-14 23:12 被阅读0次

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))

相关文章

网友评论

      本文标题:3. String & Unicode

      本文链接:https://www.haomeiwen.com/subject/sjenyttx.html