Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较Python中的数字范围_Python_Variables_Range - Fatal编程技术网

比较Python中的数字范围

比较Python中的数字范围,python,variables,range,Python,Variables,Range,我想比较数字范围。我的输出语句生成例如“25-32”。我想将数字范围与我创建的变量进行比较,这些变量看起来像A_Age=(0,2)、E_Age=range(25,32)、G_Age=range(48,53)或H_Age=range(60100)。我试过的似乎都不管用。即使我删除了偏执,或者在数字之间加了一个“-”。这就是我目前所拥有的 A_Age = range(0, 2) B_Age = range(4, 6) C_Age = range(8, 12) D_Age = range(15

我想比较数字范围。我的输出语句生成例如“25-32”。我想将数字范围与我创建的变量进行比较,这些变量看起来像A_Age=(0,2)、E_Age=range(25,32)、G_Age=range(48,53)或H_Age=range(60100)。我试过的似乎都不管用。即使我删除了偏执,或者在数字之间加了一个“-”。这就是我目前所拥有的

 A_Age = range(0, 2)
 B_Age = range(4, 6)
 C_Age = range(8, 12)
 D_Age = range(15, 20)
 E_Age = range(25, 32)
 F_Age = range(38, 43)
 G_Age = range(48, 53)
 H_Age = range(60, 100)


with open("output.txt", "r") as f:
gender = f.readline().split(":")[-1].strip()
age = f.readline().split(":")[-1].strip()
print(gender) # Male
print(age) # 25-32


if 25>= age >=32:
    print("This person is between the ages of 25 and 32...")

Python中没有内置的范围比较。你还没有描述你希望它如何工作。但是,对于初学者来说,布尔表达式是非常简单的
False

if 25>= age >=32:
    print("This person is between the ages of 25 and 32...")
你能给我举一个小于25又大于32的数字的例子吗?尝试简单的方法:

if 25 <= age <= 32:
请记住,
范围
不包括其第二个端点

if age in range(25, 32+1):