功能要求:
假定有下面这样的列表:
names = [‘pear‘, ‘peach‘, ‘banana‘, ‘apple‘]
输出结果为:‘I have pear, peach, banana and apple.‘
源代码如下:
names = [‘fentiao‘, ‘fendai‘, ‘fensi‘, ‘apple‘] print ‘I have ‘ + ‘,‘.join(names[:-1]) + ‘ and ‘ + names[-1]
结果如下:
原文地址:https://www.cnblogs.com/ChairmanYSL/p/9643748.html
时间: 2024-10-08 18:05:01