列表和元組都是按順序一個(gè)元素一個(gè)元素比較,不相等直接返回結(jié)果川抡,相等就取下一個(gè)繼續(xù)比較
如果所有元素都比較完了還沒(méi)分出大小辐真,那么元素多的大,元素一樣多則相等
>>> ["abc", "ABC", 100, 200] == ["abc", "ABC", 100, 200]
True
>>> ["abc", "ABC", 100, 200] == ["ABC", "abc", 100, 200]
False
>>> ["abc", "ABC", 100, 200].sort() == ["ABC", "abc", 100, 200].sort()
True
>>>
>>>
>>>
>>> ["abc", 100, 300] == ["abc", 200, 200]
False
>>> ["abc", 100, 300] < ["abc", 200, 200]
True
>>> ["abc", 100, -10] > ["abc", 100]
True
>>>
>>>
>>>
>>> ("abc", "ABC", 100, 200) == ("abc", "ABC", 100, 200)
True
>>> ("abc", "ABC", 100, 200) == ("ABC", "abc", 100, 200)
False
>>>
>>>
>>>
>>> ("abc", 100, 300) == ("abc", 200, 200)
False
>>> ("abc", 100, 300) < ("abc", 200, 200)
True
>>> ("abc", 100, -10) > ("abc", 100)
True
>>>
字典同樣是一個(gè)元素一個(gè)元素比較,比較的順序和字典的 keys() 函數(shù)一致
每個(gè)元素先比 key 再比 value拆祈,都相等就取下一個(gè)
如果所有元素都比較完了還沒(méi)分出大小恨闪,那么元素多的大倘感,元素一樣多則相等
>>> {"key_1":1, "key_2":2} == {"key_1":1, "key_2":2}
True
>>> {"key_3":0, "key_2":0} > {"key_1":1, "key_2":2}
True
>>> {"key_1":2, "key_2":0} > {"key_1":1, "key_2":2}
True
>>> {"key_1":1, "key_2":2, "key_3":-1} > {"key_1":1, "key_2":2}
True
>>>
集合的比較
>>> {1,2,3,4,5,6} - {1,3,5,7,9}
set([2, 4, 6])
>>> {1,2,3,4,5,6} & {1,3,5,7,9}
set([1, 3, 5])
>>> {1,2,3,4,5,6} | {1,3,5,7,9}
set([1, 2, 3, 4, 5, 6, 7, 9])
>>> {1,2,3,4,5,6} > {1,3,5,7,9}
False
>>> {1,2,3,4,5,6} > {1,3,5}
True
>>> {1,2,3} == {3,2,1}
True
>>>