码迷,mamicode.com
首页 > 其他好文 > 详细

record-11 编码解码

时间:2018-01-18 23:10:54      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:pen   python   http   import   city   coding   imp   port   编码解码   

from urllib.parse import quote,unquote

#字节码
#%E6%88%90%E9%83%BD

#quote 字符串-字节码  编码
#unquote 字节码-字符串  解码

s=‘成都‘
s1=quote(s,encoding=‘utf8‘)
print(s1)
s4=unquote(s1)
print(s4)


#字节码
#\xe6\x88\x90\xe9\x83\xbd

#encode() 编码 字符串-字节码
#decode() 解码 字节码-字符串

s=‘成都‘
s2=s.encode()
print(s2)

s3=s2.decode()
print(s3)



url1=‘http://www.sojson.com/open/api/weather/json.shtml?city=‘+s1  #%E6%88%90%E9%83%BD  这类字节码可以和字符串直接进行+运算
print(url1)
url2=‘http://www.sojson.com/open/api/weather/json.shtml?city=‘+s2  #\xe6\x88\x90\xe9\x83\xbd  这类字节码不能和字符串直接进行+运算
print(url2)

  

record-11 编码解码

标签:pen   python   http   import   city   coding   imp   port   编码解码   

原文地址:https://www.cnblogs.com/minkillmax/p/8313150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!