简体   繁体   English

如何根据一个变量包含的内容使其他变量为真?

[英]How would I make other variables True based on what one variable contains?

How would I make other variables True based on what one variable contains?如何根据一个变量包含的内容使其他变量为True

Example: If I have variables:示例:如果我有变量:

var1 = False
var2 = False
var3 = False
var4 = False
var5 = False

And I have this next line of command:我有下一行命令:

components = w.find_element_by_id('components-val')

And components returns as 1, 3, 5 , How do I make variables var1 , var3 , var5 all True ? components返回为1, 3, 5 ,如何使变量var1var3var5全部为True

Same as if I components return as 1 , 2 , the variables var1 and var2 would be True就像 I components返回12一样,变量var1var2将为True

You could save the numbers in a dictionary and then update it based on your results from compontents :您可以将数字保存在dictionary中,然后根据您的结果更新它compontents

true_false = {1: False, 2: False, 3: False, 4: False, 5: False}

components = [1,2,3]

for i in components:
    if i in true_false:
        true_false[i] = True
    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从包含多个变量的函数中仅调用一个变量? - How would I call only one variable from a function that contains multiple variables? 我想知道如何为我现有的模型表单制作基于类的视图。 我需要将一个模型表单重定向到另一个模型表单 - I would like to know how to make class based views for my existing model forms. I need to redirect the form one model form to the other 如何在其他变量列表中的列表中做其他所有事情? - How would I make every other thing in a list in a different variable list? 打印包含字符串和其他2个变量的变量 - printing variable that contains string and 2 other variables 基于多个变量分配真/假变量 - assign true/false variable based on multple variables 我将如何从一个类访问变量到另一个类? - How would I access variables from one class to another? 如何让Python读取文件行并将其用作变量? - How would I make Python read a file line and use it as a variable? 我如何将这个 for 循环的 output 变成一个字符串,变成一个变量? - How would I make the output of this for loop into a string, into a variable? 如何让这个 function 决定是否为真,而不是除以变量? - How do I make this function decide if True, than divide by variable? 我应该进行哪些更改以使我的 output 根据板上当前的 state 返回 True 或 False? - What changes should I make to make my output return True of False based on the current state on the board?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM