python基础知识

2019-03-02  本文已影响0人  长林赤焰

Anaconda操作

如何查看已经安装的库?
Anaconda环境下在PowerShell中输入以下代码:

conda list

字符串的解码和编码

Python3默认的str字符串编码方式是unicode。
decode的作用是将其他编码的字符串转换成unicode编码,如str1.decode('gb2312'),表示将gb2312编码的字符串str1转换成unicode编码。
encode的作用是将unicode编码转换成其他编码的字符串,如str2.encode('gb2312'),表示将unicode编码的字符串str2转换成gb2312编码。

>>> s_u = 'sigai'
>>> s_b = b'sigai'
>>> type(s_u)
<class 'str'>
>>> type(s_b)
<class 'bytes'>
>>> type(s_b.decode('ascii'))
<class 'str'>
>>> type(s_u.encode('ascii'))
<class 'bytes'>
>>> s_u = 'sigai在线编程'
>>> print(s_u.encode('utf-8'))
b'sigai\xe5\x9c\xa8\xe7\xba\xbf\xe7\xbc\x96\xe7\xa8\x8b'
上一篇 下一篇

猜你喜欢

热点阅读