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)时,参数xyf分别接收-56abs,根据函数定义,我们可以推导计算过程为:

x ==> -5
y ==> 6
f ==> abs
f(x) + f(y) ==> abs(-5) + abs(6) ==> 11

用代码验证一下:

>>> add(-5, 6, abs)
11
 

相关文章:

  • 2021-06-04
  • 2021-12-23
  • 2022-01-04
  • 2022-02-22
  • 2021-08-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-06-25
相关资源
相似解决方案