1 ## Say we have a list of strings we want to sort by the last letter of the string. 2 strs =['xc','zb','yd','wa'] 3 4 ## Write a little function that takes a string, and returns its last letter. 5 ## This will be the key function (takes in 1 value, returns 1 value). 6 defMyFn(s): 7 return s[-1] 8 9 ## Now pass key=MyFn to sorted() to sort by the last letter: 10 print sorted(strs, key=MyFn) ## ['wa', 'zb', 'xc', 'yd']
数组 与表类似,元不可变,大小不可变
1 tuple =('hi',) ## size-1 tuple
数组赋值时,两个数组的大小必须一致,数组中的变量可以单独使用