python怎么遍历集合

lewis 2019-03-30 23次阅读

在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



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。