# def test01(): # print("sxtsxt") # # test01() # c = test01 # c() # print(id(test01)) # print(id(c)) # print(type(c)) import math import time def test01(): start = time.time() for i in range(100000000): math.sqrt(30) end = time.time() print("耗时{0}".format((end-start))) def test02(): start = time.time() b = math.sqrt for i in range(100000000): b(30) end = time.time() print("耗时{0}".format((end-start))) test01() test02()
传递可变对象
a= [10,20] print(id(a)) print(a) print('**************') def test01(m): print(id(m)) m.append(300) print(id(m)) test01(a) print(a)
# 浅拷贝深拷贝 import copy a= [10,20,[5,6]] b= copy.copy(a) print('a:',a) print('b',b) b.append(30) b[2].append(7) print("浅拷贝.....") print("a:",a) print("b:",b) def testDeepCopy(): # 测试深拷贝 a= [10,20,[5,6]] b= copy.deepcopy(a) print('a:',a) print('b',b) b.append(30) b[2].append(7) print("深拷贝.....") print("a:",a) print("b:",b) testDeepCopy()
a= (10) print("a:",id(a)) def test01(m): print("m:",id(m)) m=20 print(m) print("m:",id(m)) test01(a)
a= (10,20,[5,6]) print("a:",id(a)) def test01(m): print("m:",id(m)) m[2][0]= 888 print(m) print("m:",id(m)) test01(a) print(a)
def test01(a,b,c,d): print('{0}-{1}-{2}-{3}'.format(a,b,c,d)) def test02(a,b,c=10,d=15): # 默认值必须位于其他参数后面 print('{0}-{1}-{2}-{3}'.format(a, b, c, d)) test01(10,20,30,40) # 位置参数 # test01(10,20) #位置参数不匹配,报错 test01(d=20,c=100,b=40,a=10) test02(2,3,4)
f = lambda a,b,c,d:a*b*c*d def test01(a,b,c,d): return a*b*c*d print(f(2,3,4,5)) g = [lambda a:a*2,lambda b:b*3] print(g[0](6)) h = [test01,test01] print(h[0](3,4,5,6))
s = 'print("abcde")' eval(s) a = 10 b = 20 c= eval("a+b") print(c) dict1 =dict (a=100,b=200) d= eval("a+b",dict1) print(d)
def test01(): print('test01') test02() def test02(): print('test02') test01()
# 使用递归函数计算阶乘 def factorail(n): if n ==1: return 1 else: return n*factorail(n-1) result = factorail(5) print(result) # 分形几何