发布时间:2019-08-05 16:08:32编辑:auto阅读(1853)
首先来设置一个原始的字符串,
Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> website = 'http://www.cnblogs.com/txw1958/' >>> type(website) <class 'str'> >>> website 'http://www.cnblogs.com/txw1958/' >>>
按utf-8的方式编码,转成bytes
>>> website_bytes_utf8 = website.encode(encoding="utf-8") >>> type(website_bytes_utf8) <class 'bytes'> >>> website_bytes_utf8 b'http://www.cnblogs.com/txw1958/' >>>
按gb2312的方式编码,转成bytes
>>> website_bytes_gb2312 = website.encode(encoding="gb2312") >>> type(website_bytes_gb2312) <class 'bytes'> >>> website_bytes_gb2312 b'http://www.cnblogs.com/txw1958/' >>>
解码成string,默认不填
>>> website_string = website_bytes_utf8.decode() >>> type(website_string) <class 'str'> >>> website_string 'http://www.cnblogs.com/txw1958/' >>> >>>
解码成string,使用gb2312的方式
>>> website_string_gb2312 = website_bytes_gb2312.decode("gb2312") >>> type(website_string_gb2312) <class 'str'> >>> website_string_gb2312 'http://www.cnblogs.com/txw1958/' >>>
上一篇: python安装教程(Win8环境)
下一篇: Ubuntu下安装opencv与pyth
49360
48552
39252
36336
30750
27559
26558
21376
21233
19580
220°
457°
444°
541°
888°
610°
1286°
1403°
1215°
1204°