Linux 拨号vps windows公众号手机端

python怎么遍历集合

lewis 6年前 (2019-03-30) 阅读数 13 #程序编程
文章标签 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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

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

热门