__lt__实际上对列表做了什么 [英] What is the __lt__ actually doing for lists

查看:104
本文介绍了__lt__实际上对列表做了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个列表,我运行以下命令

Say I have two lists, and I run the following command

>>> s = [1, 2, 3]
>>> t = [1, 2, 4]
>>> s > t
False
>>> s < t
True

但是如果我要运行以下命令

But if I were to run the following command

>>> s = [1, 2, 3]
>>> t = [1, 1, 4]
>>> s > t
True
>>> s < t
False

必须承认,我对PY3代码库不太熟悉. __lt__, __le__, __gt__, __ge__, __ne__, __eq__方法到底是怎么回事?

Have to admit, I'm not too familiar with the PY3 codebase. What exactly is going on in the __lt__, __le__, __gt__, __ge__, __ne__, __eq__ methods?

推荐答案

比较是词典.如果您阅读了它的定义,那么您将了解所有内容.

The comparison is lexicographical. If you read the definition of that, you will understand everything.

按顺序迭代成对的元素,第一个不相等的对确定顺序的获胜者.

Iterate the pairs of elements in order, and the first non-equal pair determines the winner of the ordering.

这篇关于__lt__实际上对列表做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆