python - 如何比较版本号python
问题描述
如果我有这个
a = "4.1.3.79"
b = "4.1.3.64"
我怎样才能进行这种比较以返回True?
a > b
我不能使用float()
orint()
并且 python 不能将 4.1.2.79 识别为数字,我该如何与这些类型的值进行比较?
我已经阅读了,StrictVersion
但这只会上升到第 3 个版本号,而不是 4。
解决方案
这将起作用:
a = "4.1.2.79"
b = "4.1.3.64"
#split it
a_list = a.split('.')
b_list = b.split('.')
#to look if a is bigger or not
a_bigger = False
#compare it number by number in list
for i in range(0, len(a_list)):
#make from both lists one integer
a_num = int(a_list[i])
b_num = int(b_list[i])
#if one num in the a_list is bigger
if a_num > b_num:
#make this variable True
a_bigger = True
#break the loop so it will show the results
#else it wil look to the other nums in the lists
#print the result
print('a > b: %s' % str(a_bigger))
推荐阅读
- ios - 减少 LineChartView 中点的频率?
- python - 执行图例函数时出现“名称'scatter'未定义”错误
- python - 如何通过xpath获取所有H4元素
- python - 在 Python 3 中从字典中打印键或值
- python-3.x - 使用 python 将特定的雅虎财务在线表格导出到 csv
- java - 如果 git 是版本控制,如何将 spring 云配置服务器指向由客户端决定的文件夹
- reactjs - 如何使用 webpack-dev-server 从我的反应应用程序中的 src 文件夹中读取 json 文件?
- python - 如何更改交互式缩放矩形的颜色?
- c - 将函数的返回值存储在数组中
- angular - 如何同时实时运行 Angular 服务、测试和 lint?