【问题标题】:If statement for all values in list python列表python中所有值的if语句
【发布时间】:2015-12-06 11:48:59
【问题描述】:

我想知道如何获取所有列表索引的 if 语句

#a = int(input("a "))
a = [10,10,10]
#b = int(input("b "))
b = [100,10,10]
#c = int(input("c "))
c = [10,10,10]
#d = int(input("d "))
d = [100,10,10]

for itema in a:
    print itema
for itemb in b:
    print itemb
for itemc in c:
    print itemc
for itemd in d:
    print itemd

if itema>=itemd:
    print "make math equation nr.1"
elif itemb<itemd:
    print "make math equation nr.2"

我尝试通过列表中的所有元素检查我的状况并获取结果列表。我应该使用哪些技术?

【问题讨论】:

    标签: list python-2.7 if-statement for-loop


    【解决方案1】:

    这可能会有所帮助:

    for itema, itemb, itemd in zip(a, b, d):
        if itema > itemd:
            print('eq 1')
        elif itemb < itemd:
            print('eq. 2')
    

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 2023-03-13
      • 2020-07-09
      • 1970-01-01
      • 2020-09-28
      • 2015-07-15
      • 2015-12-06
      • 2020-07-30
      • 2020-08-07
      相关资源
      最近更新 更多