1.>>> d = {‘x‘: ‘A‘, ‘y‘: ‘B‘, ‘z‘: ‘C‘ }
>>> for k, v in d.iteritems():
... print k, ‘=‘, v
...
y = B
x = A
z = C
2.>>> L = [‘Hello‘, ‘World‘, ‘IBM‘, ‘Apple‘]
>>> [s.lower() for s in L]
[‘hello‘, ‘world‘, ‘ibm‘, ‘apple‘]
3.
def add(x, y, f):
return f(x) + f(y)
当我们调用add(-5, 6, abs)
时,参数x
,y
和f
分别接收-5
,6
和abs
,根据函数定义,我们可以推导计算过程为:
x ==> -5
y ==> 6
f ==> abs
f(x) + f(y) ==> abs(-5) + abs(6) ==> 11
用代码验证一下:
>>> add(-5, 6, abs)
11
时间: 2024-10-28 04:16:35