Python 为什么使用循环打印时订单排序不正确?

Python 为什么使用循环打印时订单排序不正确?,python,python-3.x,Python,Python 3.x,我试图运行这个循环,但是结果的顺序是这样的 student_name = {"Karrie", "Freya", "Bruno"} for name in student_name: print("The student name is {0}".format(name)) 集合是无序的。如果要查找有序集合,请使用以下列表: The student name is Freya The student name is Karrie The student name is Bruno 使用已排

我试图运行这个循环,但是结果的顺序是这样的

student_name = {"Karrie", "Freya", "Bruno"}

for name in student_name:
print("The student name is {0}".format(name))

集合是无序的。如果要查找有序集合,请使用以下列表:

The student name is Freya
The student name is Karrie
The student name is Bruno
使用已排序的:

student_name = ["Karrie", "Freya", "Bruno"]

for name in student_name:
    print("The student name is {0}".format(name))
集合像字典一样无序。根据需求使用列表/元组。。
student_name = {"Karrie", "Freya", "Bruno"}
for name in sorted(student_name):
    print("The student name is {0}".format(name))