Python int与string之间的转化

string-->int
1、10进制string转化为int
  int('12')
2、16进制string转化为int
  int('12', 16)
int-->string
1、int转化为10进制string
  str(18)
2、int转化为16进制string
  hex(18)
 
json转化为字典
import json json_str = """ { "id" : 90, "name" : "python", "url" : "http://www.v2ex.com/go/python", "title" : "Python", "title_alternative" : "Python", "topics" : 7646, "stars" : 4862, """ res = json.loads(json_str) print(res['id']) # 90 print(res['name']) # python print(res['url']) # http://www.v2ex.com/go/python
原文地址:https://www.cnblogs.com/TomBombadil/p/10980047.html