How does tuple comparison work in Python?

前端 未结 4 1818
梦毁少年i
梦毁少年i 2020-11-22 04:26

I have been reading the Core Python programming book, and the author shows an example like:

(4, 5) < (3, 5) # Equals false

So,

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 04:57

    The Python documentation does explain it.

    Tuples and lists are compared lexicographically using comparison of corresponding elements. This means that to compare equal, each element must compare equal and the two sequences must be of the same type and have the same length.

提交回复
热议问题