python_字符串有时可以比较大小哦!

1、字符串纯数字

s='123'
t='234'
if s>t:
    print("s>t")
else:
    print("s<t")



D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
s<t

 

2、字符串数字+字母

按首字母进行比大小

s='a123'
t='b23'
if s>t:
    print("s>t")
else:
    print("s<t")

D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
s<t
s='c123'
t='b23'
if s>t:
    print("s>t")
else:
    print("s<t")


D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
s>t

 

3、字符串字母

s='cddd'
t='bggg'
if s>t:
    print("s>t")
else:
    print("s<t")


D:\study\python\test\venv\Scripts\python.exe D:/study/python/test/dd.py
s>t

 

posted @ 2019-06-18 16:47  小戳同学  阅读(16776)  评论(1编辑  收藏  举报