集合遍历
可以使用 for 循环遍历集合中的元素。
fruits = {"apple", "banana", "orange"}
for fruit in fruits:
print(fruit)
集合推导式
可以使用集合推导式创建新的集合。
numbers = [1, 2, 3, 4, 5]
squares = {x**2 for x in numbers} # {1, 4, 9, 16, 25}
集合遍历
可以使用 for 循环遍历集合中的元素。
fruits = {"apple", "banana", "orange"}
for fruit in fruits:
print(fruit)
集合推导式
可以使用集合推导式创建新的集合。
numbers = [1, 2, 3, 4, 5]
squares = {x**2 for x in numbers} # {1, 4, 9, 16, 25}
版权声明:本文内容系天翼云实名用户自发贡献,版权归原作者所有,天翼云开发者社区不拥有其著作权,亦不承担相应法律责任,未经许可,不得转载。
如有疑问或争议,请联系ctyunbbs@chinatelecom.cn删除。
集合遍历
可以使用 for 循环遍历集合中的元素。
fruits = {"apple", "banana", "orange"}
for fruit in fruits:
print(fruit)
集合推导式
可以使用集合推导式创建新的集合。
numbers = [1, 2, 3, 4, 5]
squares = {x**2 for x in numbers} # {1, 4, 9, 16, 25}
版权声明:本文内容系天翼云实名用户自发贡献,版权归原作者所有,天翼云开发者社区不拥有其著作权,亦不承担相应法律责任,未经许可,不得转载。
如有疑问或争议,请联系ctyunbbs@chinatelecom.cn删除。