为什么在使用循环打印时,订单未正确排序?

时间:2018-06-21 08:24:49

标签: python python-3.x

mysql DatabaseName -u DBuser -p DBPassword < path/to/mysql/file.sql

我正在尝试运行此循环,但结果以这种形式排列

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

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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

使用已排序:

student_name = {"Karrie", "Freya", "Bruno"}
for name in sorted(student_name):
    print("The student name is {0}".format(name))