python中set怎么循环_python如何遍历set
生活随笔
收集整理的这篇文章主要介绍了
python中set怎么循环_python如何遍历set
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1、利用迭代器进行迭代遍历:Set sets = new HashSet();
Iterator it = set.iterator();
while (it.hasNext()) {
String str = (String)it.next();
System.out.println(str);
}
2、for循环遍历:for (String str : sets) {
System.out.println(str);
}
3、foreach循环遍历:Set set = new HashSet();
for (Object obj: sets) {
if(obj instanceof Integer){
int aa= (Integer)obj;
}else if(obj instanceof String){
String aa = (String)obj
}
……..
}
python学习网,大量的免费python视频教程,欢迎在线学习!
总结
以上是生活随笔为你收集整理的python中set怎么循环_python如何遍历set的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 基于产生式的动物识别专家系统_钇鑫智通打
- 下一篇: python属性使用教程_Python对