温馨提示×

python怎么遍历集合

养鱼的猫咪
1671
2021-03-08 17:20:27
栏目: 编程语言

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

0