record-11 编码解码

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)


#字节码
#xe6x88x90xe9x83xbd

#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  #xe6x88x90xe9x83xbd  这类字节码不能和字符串直接进行+运算
print(url2)

  

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