# coding: utf-8
goal_str = ''
def translate(list):
global goal_str # 定义全局变量
for i in range(len(list) - 1):
goal_str += list[i] + ','
goal_str += 'and ' + list[-1]
return goal_str
spam = ['apples', 'bananas', 'tofu', 'cats']
print(translate(spam))
逗号代码
最新推荐文章于 2021-03-29 21:09:43 发布