各种编程语言存储数据的容器不尽相同,在Python中有字典dict这样的数据类型,而其他语言可能没有对应的字典,为了让不同的语言都能够相互通用的传递数据,JSON就是一种非常良好的中转数据格式,如下: JSON其实是一种有特定格式的字符串,它通过函数要么可以转换为Python的字典,要么可以转换为Python的列表, Python的列表和字典也可以通过函数转换为JSON, 其中列表的格式需要内部元素都是字典,如下: import  json
data =  [ { "name" :  "张大仙" , "age" :  11 } ,{ "name" :  "王大锤" , "age" :  9 } ,{ "name" :  "赵啸虎" , "age" :  16 } ] json_str =  json.dumps( data, ensure_ascii = False)  
print( type( json_str))    
print( json_str)  data2 =  { "周杰伦" :  "台北" } 
json_str2 =  json.dumps( data2, ensure_ascii = False) 
print( type( json_str2))   
print( json_str2)     
data3 =  '[{"name": "张大仙", "age": 11},{"name": "王大锤", "age": 9},{"name": "赵啸虎", "age": 16}]' 
print( type( json.loads( data3)) )   
print( json.loads( data3))     data4 =  '{"周杰伦": "台北"}' 
print( type( json.loads( data4)) )   
print( json.loads( data4))     
语法:’{}’. format() ,用于格式化字符串,可以接收无限参数,可以指定顺序,返回字符串 举例,如下: 
'学习{}中的{}函数' .format( 'python' ,'format' ) 
-> '学习python中的format函数' 
'学习{1}中的{0}函数' .format( 'format' ,'python' ) 
-> '学习python中的format函数' 
list1 =  [ 'hello' ,'say' ,'world' ,'s' ]   
'LiMing {0[1]}{0[3]} {0[0]} to {0[2]}' .format( list1) 
-> 'LiMing says hello to world' 
list1 =  [ 'hello' ,'say' ]   
list2 =  [ 'world' ,'s' ] 
'LiMing {0[1]}{1[1]} {0[0]} to {1[0]}' .format( list1,list2) 
-> 'LiMing says hello to world'