python字符串比较大小

理解原理和相关知识

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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值