a = [apple,[green,red,yellow]]
print(a[0]+ " available in these colours " + a[1[]])
如何在列表项中将字符串与列表连接起来?
预期结果 :-
apple available in these collars green red yellow
假设您开始
a = ['apple',['green', 'red', 'yellow']]
然后a[0]
是一个字符串,是一个字符串a[1]
列表。您可以使用更改a[1]
为字符串', '.join(a[1])
,使用逗号和空格将它们连接起来。
所以
a[0] + ' available in ' + ', '.join(a[1])
应该可以工作,因为您可以使用来连接字符串+
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句