在python中對集合進行遍歷的方法有以下兩種
1.使用for循環對集合進行遍歷
A = {'1','2','star'}for item in A:print(item,end='')
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
try:
while True:
print(A.pop(),end='')
except:
pass