如何获取 List.__gt__() func 的源码实现

How can i get the source implement of List.__gt__() func

我是一个新的 Python 程序员,我的代码如下,我很困惑为什么我得到 true 的结果。 好像调用了List的__gt__内置函数。 我不知道从哪里可以得到List.gt().

的内部(内置)函数的源代码
L1 = ['abc', ['123', '456']]
L2 = ['1', '2', '3']
print(L1 > L2)

如果有人给出答案,我会非常感谢。

该行为在文档中有详细说明,因此您实际上不需要阅读源代码来理解它(但请务必在本答案末尾查看我的评论):

Sequence objects may be compared to other objects with the same sequence type. The comparison uses lexicographical ordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted. If two items to be compared are themselves sequences of the same type, the lexicographical comparison is carried out recursively. If all items of two sequences compare equal, the sequences are considered equal. If one sequence is an initial sub-sequence of the other, the shorter sequence is the smaller (lesser) one.

https://docs.python.org/3/tutorial/datastructures.html#comparing-sequences-and-other-types

值得注意的是,Python 3 不再允许比较任意对象对(在 Python 2 中就是这种情况)。这可以通过稍微修改您的示例来说明:

>>> L1 = ['1', ['123', '456']]
>>> L2 = ['1', '2', '3']
>>> print(L1 > L2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: list() > str()

但是,如果阅读了所有这些内容,您仍然希望阅读 CPython 源代码,它位于 https://github.com/python/cpython

具体来说,列表比较代码可以在https://github.com/python/cpython/blob/master/Objects/listobject.c#L2634

找到