集合操作①定义集合。vegetables = cabbage potato tomato cucumberfruits = apple orange banana tomato cucumber②遍历集合。输出fruits所有元素。③添加集合元素。添加 peach到fruits。python编写
①
vegetables = {'cabbage', 'potato', 'tomato', 'cucumber'}
fruits = {'apple', 'orange', 'banana', 'tomato', 'cucumber'}
②
for fruit in fruits:
print(fruit)
输出结果:
apple
orange
banana
tomato
cucumber
③
fruits.add('peach')
现在fruits集合中包含 'peach' 元素。
原文地址: https://www.cveoy.top/t/topic/fK3h 著作权归作者所有。请勿转载和采集!