一、传参测试
1 n=10 2 li=[1,2,3] 3 4 def test01(n): 5 n=n+1 6 test01(n) 7 print(n) #10 8 9 def test02(li): 10 li.append(4) 11 test02(li) 12 print(li) #[1, 2, 3, 4] 13 14 #列表改变了,数字没有改变 15 ''' 16 字符串,数字,元组是immutable对象, 17 列表,字典是mutable对象 18 '''
二、匿名函数练习实例
n=lambda a,b,c:a+b+c print(n(10,20,30)) #60
三、json模块
1 #test1------------------------------------------------------> 2 import json 3 dic={'name':'child'} 4 data=json.dumps(dic)#被josn的dumps后,dic变成了字符串 5 print(type(data))#此时的字符串是一个json字符串 <class 'str'> 6 print(data) #{"name": "child"} 7 8 9 10 #test2-------------------------------------------------------> 11 12 import json 13 with open('human','w') as f: 14 dic={'gender':'man','health':'good'} 15 data=json.dumps(dic) 16 f.write(data) 17 18 with open('human','r') as f: 19 data=json.loads(f.read()) 20 print(data) #{"gender": "man", "health": "good"}