[英]How to check several conditions at the same time in python?
The actual question is: I want to check the state of charge of several batteries at the same time and perform actions(charge/discharge/amount of charge/discharge) in parallel, based on the values obtained.实际问题是:我想同时检查几个电池的充电 state 并根据获得的值并行执行操作(充电/放电/充电/放电量)。
If T
is an object:如果T
是 object:
all([T[i] == 1 for i in range(1,51)])
If T
is a function:如果T
是 function:
all([T(i) == 1 for i in range(1,51)])
all
Is a built-in function that checks whether every one item in the list is evaluable to True
(may those be True
itself, or 1
, a non-empty string or list, ...) all
是一个内置的 function ,它检查列表中的每个项目是否都可以评估为True
(可能是True
本身,或者1
,非空字符串或列表,...)
The expression [f(x) for x in iterable]
is called list comprehension and is a shortcut to create a list, equivalent to:表达式[f(x) for x in iterable]
称为列表推导,是创建列表的快捷方式,相当于:
l = []
for x in iterable:
l.append(f(x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.