此版本号比较能够处理含数字、点“.”、英文字母等多种,定长和不定长的版本号的比较。
如有疑问和指教,欢迎留言。
def compare(version1, version2):
v1 = version1.split('.')
v2 = version2.split('.')
while v1 and v2:
x, y = v1.pop(0), v2.pop(0)
if x.isdigit() and y.isdigit():
if int(x) == 0 and int(y) == 0:
pass
else:
if x > y:
return 1 #version1 > version2
if x < y:
return -1 # version1 < version2
else:
if x > y:
return 1 # version1 > version2
if x < y:
return -1 #version1 < version2
if v1:
for x in v1:
if x.isdigit():
if int(x) == 0:
v1.pop(0)
else:
return 1 #version1 > version2
else:
return 1 #version1 > version2
if

本文介绍如何处理包含数字、点和字母的版本号比较,包括定长和不定长的版本号。提供相关参考资料。
最低0.47元/天 解锁文章
1333

被折叠的 条评论
为什么被折叠?



