立即学习:https://edu.csdn.net/course/play/26676/338788?utm_source=blogtoedu
>>> def foo(a):
a.append(99)
return a
>>> lst=[1,2,3]
>>> lst.append(0)
>>> lst
[1, 2, 3, 0]
>>>
函数也是对象(object)
bar() 调用/ 执行这个对象
>>> def opt_seq(func,seq):
r=[func(i)for i in seq]
return r
>>> abs(-2)
2
>>> opt_seq(abs,range(-5,5))
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]
>>> opt_seq(str,[1,2,3])
['1', '2', '3']
>>> a=1
>>> def f3():
global a
a=a+1
print (a)
>>> f3()
2
>>> def foo():
a=1
def bar():
nonlocal a
a=a+1
print(a)
bar()
>>> foo()
2
def w(m,g): return m * g def weight(g): def cal_mg(m): return m * g return cal_mg w=weight(10) # g=10 G=w(100) G2=w(50) print(G) w2=weight(9.7846) G3=w2(100) print(G3)