Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在三种情况下使用三个值对参数进行编码_Python_Variables_Parameters - Fatal编程技术网

Python 如何在三种情况下使用三个值对参数进行编码

Python 如何在三种情况下使用三个值对参数进行编码,python,variables,parameters,Python,Variables,Parameters,我有一个叫做f的参数。。我不知道如何编码,我应该把它作为一个列表还是需要一个if循环 f = 1 if the indicator i exists in list 1 f = -1 if the indicator i exists in list 2 f = O otherwise 我将在右侧等于f的约束中使用参数f 有什么帮助吗? 如果需要进一步澄清,我已准备好 您可以在python中的一行中完成此操作: f = 1 if i in list1 else -1

我有一个叫做f的参数。。我不知道如何编码,我应该把它作为一个列表还是需要一个if循环

   f = 1  if the indicator i exists in list 1
   f = -1 if the indicator i exists in list 2
   f = O  otherwise 
我将在右侧等于f的约束中使用参数f

有什么帮助吗? 如果需要进一步澄清,我已准备好


您可以在python中的一行中完成此操作:

f = 1 if i in list1 else -1 if i in list2 else 0

meI还不清楚这个问题是否已经解决了是什么阻止了您编写
if/elif/else
?您似乎需要有关基本语言功能的教程帮助。堆栈溢出不用于替换现有教程。完成循环、列表和
if
语句的部分。这是因为我只是一个新手。好的,谢谢,我会尝试的。