numbers are compared by relative magnitudeafter conversion to the common highest type if needed strings are compared lexicographically (by the character set code point values returned by ord)and character by character until the end or first mismatch ("abc"ac"lists and tuples are compared by comparing each component from left to rightand recursively for nested structuresuntil the end or first mismatch ([ [ ]sets are equal if both contain the same items (formallyif each is subset of the other)and set relative magnitude comparisons apply subset and superset tests dictionaries compare as equal if their sorted (keyvaluelists are equal relative magnitude comparisons are not supported for dictionaries in python xbut they work in as though comparing sorted (keyvaluelists nonnumeric mixed-type magnitude comparisons ( 'spam'are errors in python they are allowed in python xbut use fixed but arbitrary ordering rule based on type name string by proxythis also applies to sortswhich use comparisons internallynonnumeric mixed-type collections cannot be sorted in in generalcomparisons of structured objects proceed as though you had written the objects as literals and compared all their parts one at time from left to right in later we'll see other object types that can change the way they get compared python and mixed-type comparisons and sorts per the last point in the preceding section' listthe change in python for nonnumeric mixed-type comparisons applies to magnitude testsnot equalitybut it also applies by proxy to sortingwhich does magnitude testing internally in python these all workthough mixed types compare by an arbitrary orderingc:\codec:\python \python =' false >' false [' '' 'sort([ ' 'sort(equality does not convert non-numbers compares by type name stringintstr ditto for sorts but python disallows mixed-type magnitude testingexcept numeric types and manually converted typesc:\codec:\python \python =' xequality works but magnitude does not false >' typeerrorunorderable typesint(str( tuplesfilesand everything else