Python 如何测试多个条件(经度和纬度)?

Python 如何测试多个条件(经度和纬度)?,python,conditional-statements,Python,Conditional Statements,所以我试图分析特定时区的推特情绪值。我试图检查具有特定经纬度坐标的特定时区。如何测试if语句中的多个条件?还是在for循环中?我放括号还是什么 for line in infile: line=line.rstrip() words=line.split() firststriplat=words[0].rstrip(",") lat=firststriplat.lstrip("[") lat=float(lat)

所以我试图分析特定时区的推特情绪值。我试图检查具有特定经纬度坐标的特定时区。如何测试if语句中的多个条件?还是在for循环中?我放括号还是什么

 for line in infile:
        line=line.rstrip()
        words=line.split()
        firststriplat=words[0].rstrip(",")
        lat=firststriplat.lstrip("[")
        lat=float(lat)
        long=words[1].rstrip("]")
        long=float(long)
        easternlat=lat>=24.660845 and lat=<49.189787
        easternlong=long>=-87.518395 and long=<-67.444574
        if easternlat and easternlong:
对于内嵌中的行:
line=line.rstrip()
words=line.split()
firststriplat=words[0].rstrip(“,”)
lat=firststriplat.lstrip(“[”)
横向=浮动(横向)
long=字[1]。rstrip(“]”)
长=浮动(长)

easternlat=lat>=24.660845和lat==-87.518395和long=使用括号,您测试的是什么类型的条件?即有多少种

例如,如果有多个>和==

你可以这样做


(Con A==Con B)和(conC==conD)

在Python中,可以执行类似的操作来检查变量是否在特定范围内:

if (24.660845 <= lat <= 49.189787) and (-87.518395 <= long <= -67.444574):
    pass

如果(24.660845)您确实尝试过这个代码吗?它以什么方式不符合您的要求?请阅读。逻辑表达式可以像算术表达式一样与
分组。嘿,谢谢您的回答。这很有意义。您能为for循环这样做吗?