python——字符串比较大小,使用opreater库

python3中没有cmp的函数,所以我们要导入opreater库,用库中比较函数来比较。

首先教大家几个英文:

大于:greater than

小于:less than

等于:equal

所以库中的大于就是gt,小于lt,等于eq,

import operator as op
if (op.gt("123","100")):
    print("greater than")
if(op.lt("100","123")):
    print("less than")

猜你喜欢

转载自blog.csdn.net/qq_23418043/article/details/80672607