功能要求:app
假定有下面這樣的列表:
names = ['pear', 'peach', 'banana', 'apple']
輸出結果爲:'I have pear, peach, banana and apple.'spa
源代碼以下:code
names = ['fentiao', 'fendai', 'fensi', 'apple'] print 'I have ' + ','.join(names[:-1]) + ' and ' + names[-1]
結果以下:blog