python中如何求出array数组中大于a且小于b的元素的索引

在数组c 中 找出大于a且小于b的元素的索引

代码如下

c = [1, 3, 9, 4, 6, 7]
a = 2
b = 6

for num in c:
    if a < num & num < b:
        print("符合条件的数值为:", num, ",id为:", c.index(num))

# 输出如下
# 符合条件的数值为: 3 ,id为: 1
# 符合条件的数值为: 4 ,id为: 3
# 使用c.index(num)函数来获取元素的索引

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-07-03
好像就只能用循环来解决
for i in range(len(A)):
if(-1<A[i]<1):
……
相似回答