Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.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 - Fatal编程技术网

Python 如何将字符转换为变量?

Python 如何将字符转换为变量?,python,Python,详细内容: 我需要这个公式来工作。 string=str(z)+“:1.0”+str(z+1)+“:0.0”其中z是一个带值的变量 我能用一个特定的键将这个公式输入到字典值中吗。像 dicto={'A': 'str(z)+":1.0 "+str(z+1)+":0.0"'} 因此,当我看到键值“a”时,我应该能够在字典中使用该公式使用: 使用: 当我读到你的问题时,你想要这样的东西: dicto = {'A': lambda x: "{0!s}:1.0 {1!s}:0.0".format

详细内容: 我需要这个公式来工作。
string=str(z)+“:1.0”+str(z+1)+“:0.0”
其中z是一个带值的变量

我能用一个特定的键将这个公式输入到字典值中吗。像

dicto={'A': 'str(z)+":1.0 "+str(z+1)+":0.0"'}    
因此,当我看到键值“a”时,我应该能够在字典中使用该公式

使用:

使用:


当我读到你的问题时,你想要这样的东西:

dicto = {'A': lambda x: "{0!s}:1.0 {1!s}:0.0".format(x, x + 1)}
dicto['A'](2)   # '2:1.0 3:0.0'

当我读到你的问题时,你想要这样的东西:

dicto = {'A': lambda x: "{0!s}:1.0 {1!s}:0.0".format(x, x + 1)}
dicto['A'](2)   # '2:1.0 3:0.0'

我想你想要一个函数,而不是一个变量。我想你想要一个函数,而不是一个变量。