首页 > 其他 > 详细

record-11 编码解码

时间:2018-01-18 22:41:56      阅读:221      评论:0      收藏:0      [点我收藏+]
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 编码解码

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!