[英]Checking a list of string variables is a particular string
I have a list of string我有一个字符串列表
[a,b,c]
How do I check if all the variables are the string 'Ready'?.如何检查所有变量是否都是字符串“Ready”?
I want to return True if all variables are Ready
else False.如果所有变量都
Ready
,我想返回 True,否则返回 False。
I really appreciate any help you can provide.我非常感谢您能提供的任何帮助。
You can use all
and a list comprehension:您可以使用
all
和列表推导:
lst = ['Ready', 'Ready', 'Ready']
print(all(i == 'Ready' for i in lst))
Output: Output:
True
Thanks for @schwobaseggl's comment, you can also do this:感谢@schwobaseggl 的评论,您也可以这样做:
print(all(map("Ready".__eq__, lst)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.