1
A
回答
9
您可以使用absolute value:
if abs(x-1) < abs(variable-1):
...
因爲x-1
絕對值x
和1
,同樣之間的距離variable-1
絕對值variable
和1
之間的距離。
相關問題
- 1. 的Python向最接近0.25
- 2. 最快的方法來獲得最接近1在Python中的字典鍵
- 3. 最接近的值
- 4. 父VS最接近
- 5. python近似最近鄰居庫(WINDOWS)
- 6. 最接近()沒有返回最接近我的輸入標籤
- 7. 獲取最接近的元素使用jQuery最接近()函數
- 8. vba如果它匹配找到最接近的日期
- 9. 在python中,如何選擇最接近0的整數?
- 10. 如何打開最接近指定文件的文件python
- 11. Python 2中最接近的Python 2樣式打印3
- 12. 如何選擇最接近類和它的id最接近方法
- 13. 接近最近鄰居搜索
- 14. Python:最近指向一行
- 15. 最近鄰搜索:Python的
- 16. 在django模板中將數字舍入到最接近的1
- 17. MySQL獲得最接近1歲的紀錄
- 18. 四捨五入到C的1/16的最接近倍數
- 19. 尋找BeautifullSoup的最接近的鏈接(python)
- 20. 最接近的整除
- 21. 最接近的元素MATLAB
- 22. 得到最接近的
- 23. 尋找最近的鏈接
- 24. JQuery最接近()返回undefined
- 25. MySQL的:最接近行
- 26. 抓最接近的元素
- 27. jquery最接近不工作
- 28. 價格最接近陣列?
- 29. jquery最接近元素值
- 30. 獲取最接近的值