>>> ord('a') 97
>>> string='abcde' >>> def change(string): res=[] for alpha in string: res.append(ord(alpha)) return res >>> change(string) [97, 98, 99, 100, 101] >>>
>>> list(map(ord,'abcde')) [97, 98, 99, 100, 101] >>>
>>> res=[ord(x) for x in 'abcde'] >>> res [97, 98, 99, 100, 101] >>>
>>> aList=[1,2,3,4,5] >>> def sqrt(aList): for x in range(len(aList)): aList[x]*=aList[x] >>> sqrt(aList) >>> aList [1, 4, 9, 16, 25] >>>
>>> aList=[1,2,3,4,5] >>> def sqrt(x): return x*x >>> list(map(sqrt,aList)) [1, 4, 9, 16, 25] >>>
>>> list(map(lambda x:x**2,[1,2,3,4,5])) [1, 4, 9, 16, 25] >>>
>>> [x**2 for x in [1,2,3,4,5]] [1, 4, 9, 16, 25] >>>
这一章节就说到这里,谢谢大家
------------------------------------------------------------------
点击跳转零基础学python-目录