Python 为什么字符串(字典)中的元素会自动改变位置?

Python 为什么字符串(字典)中的元素会自动改变位置?,python,string,list,dictionary,Python,String,List,Dictionary,库版本。。。 python:3.7.4.final.0 熊猫:1.0.0 numpy:1.18.1 strings = {'one','two','three','four'} stri = ["one",'two','three','four'] print("strings={} \n stri={}".format(strings, stri)) #elements in strings changes position!!!

库版本。。。 python:3.7.4.final.0 熊猫:1.0.0 numpy:1.18.1

strings = {'one','two','three','four'} 
stri = ["one",'two','three','four']     
print("strings={} \n stri={}".format(strings, stri))   

#elements in strings changes position!!!   output:    strings={'four', 'two', 'three', 'one'} 
#elements in stri remains in same order!!!   output:  stri=['one', 'two', 'three', 'four']

为什么字符串中的元素会改变顺序?

集合是无序集合。他们没有秩序,这就是为什么你不能这样做:

mySet[0]

这不是一本字典,它是一个
集合
集合
s与
列表
s不同,是无序的。@Selcuk检查我的更新答案。。我无意中把它称为词典,但我的意思是set