前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python字符串比较大小

python字符串比较大小

作者头像
用户7886150
修改2021-01-19 10:20:48
1.3K0
修改2021-01-19 10:20:48
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: Python字符串String

理解原理和相关知识 

字符串按位比较,两个字符串第一位字符的ascii码谁大,字符串就大,不再比较后面的;第一个字符相同就比第二个字符串,以此类推,需要注意的是空格的ascii码是32,空(null)的ascii码是0 https://zhidao.baidu.com/question/558202137825309252.htmlord 函数接受一个字符 

print(max(['1', '2', '3']))  # 3

print(max(['31', '2', '3']))  # 31

print(max(['13', '2', '3']))  # 3

print(max(['10', '11', '12']))  # 12

print(max(['13', '11', '12']))  # 13

print(ord('1'))  # 49

print(ord('2'))  # 50

print(ord('3'))  # 51

# print(ord('10')) TypeError: ord() expected a character, but string of length 2 found

print(ord(' '))  # 32

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档