python - 编写此 if 语句的更好方法?

标签 python comparison

我有这个 tkinter GUI,我需要从条目中获取值并进行比较。 self.hystInt.get()是在Entry中的string变量中访问string的方式。 *我必须为每个变量都写这个,所以它最终看起来真的很难看。

if (self.hystInt.get().isdigit() and int(self.hystInt.get()) >= 200 and int(self.hystInt.get()) <= 500):

最佳答案

def validate(num):
    try:
        return 200 <= int(num) <= 500
    except ValueError:
        return False

简单就是好!

关于python - 编写此 if 语句的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4072871/

相关文章:

typescript 部分接口(interface)奇怪的行为

python - 将日期插入 DataFrame 的行中

java - 是否可以在一个网站上使用多种编程语言

python - Django 查询返回空字符串

python - 遍历嵌套字典

java - 如何仅使用 7 次比较对 5 项进行排序

xml - 在 Flash 中使用 json 而不是 xml 的任何特殊优势

python - 使用 pandas 通过文本相似度合并两个数据框

algorithm - 排序列表差异

content-management-system - 如何为小型网站选择 CMS/门户解决方案?