Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 606 Bytes

14.md

File metadata and controls

30 lines (23 loc) · 606 Bytes
@author jackzhenguo
@desc 
@date 2019/2/15

14 字符串转字节  

字符串转换为字节类型

In [12]: s = "apple"                                                            

In [13]: a = bytes(s,encoding='utf-8')   
In [14] a 
Out[14]: b'apple'

# 转化后a变为字节序列,bytes类型,
# 并且每个字符都被转化为数值,如下所示
In [15]: for i in a: 
    ...:     print(i)                                                                       
97
112
112
108
101
[上一个例子](13.md) [下一个例子](15.md)