python 遍历

python怎么遍历集合

养鱼的猫咪
1686
2021-03-08 17:20:27
栏目: 编程语言
Python开发者服务器,限时0元免费领! 查看>>

python怎么遍历集合

在python中对集合进行遍历的方法有以下两种

1.使用for循环对集合进行遍历

A = {'1','2','star'}

for item in A:

print(item,end='')

2.使用while对集合进行循环遍历

A = {'1','2','star'}

try:

while True:

print(A.pop(),end='')

except:

pass

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:怎么在Python中遍历集合

0
看了该问题的人还看了