简体   繁体   English

如何在 python 中同时检查多个条件?

[英]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.

相关问题 如何在Python中连续检查多个项目中的条件? - How to check conditions in several items in a row in Python? 如何在 Selenium/Python 中检查几个条件 - How to check several conditions in Selenium/Python 如何在python的for循环中同时检查两个条件? - How do I check two conditions at the same time in a for loop in python? 如何在Python中同时检查多个行中多个列的多个并发事件? - How to check for multiple concurrent events in several rows for several columns at the same time in Python? 一个大的 numpy 数组(5 列 300 万行)——如何选择同时满足多个条件的行? Python 3.8.8 - One large numpy array (3mil rows on 5 columns) - how to pick rows that meet several conditions at the same time? Python 3.8.8 如何在包含多个子列表的列表中检查多个条件? - How can I check several conditions on a list containing several sublist? 如何同时从多个 python 线程正确写入日志文件? - How to properly write to logfile from several python threads at the same time? 如何在python中同时运行多个循环函数? - How to run several looping functions at the same time in python? 如何在python中使用.endswith函数测试几个条件 - How to test several conditions with .endswith function in python Python 如果不等于几个条件 - Python If not equal several conditions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM