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

Python 无法将变量插入字符串中

Python 无法将变量插入字符串中,python,string,Python,String,我对Python有点陌生,在这一刻我被卡住了: c = 5 cmds.pointPosition(geo[0]+".cv[0]["+c+"2]", w=True) 这给了我一个错误: 错误:TypeError:文件第39行:强制使用Unicode: 需要字符串或缓冲区,找到int# 问题是如何将变量c=5放在第二个括号内,使其成为7 尽可能避免字符串连接。这是一个很好的用例 假设c保留一个整数的值作为开始(否则,c+2步骤失败)。尽可能避免字符串串联。这是一个很好的用例 假设c持有一个整数的值

我对Python有点陌生,在这一刻我被卡住了:

c = 5
cmds.pointPosition(geo[0]+".cv[0]["+c+"2]", w=True)
这给了我一个错误:

错误:TypeError:文件第39行:强制使用Unicode: 需要字符串或缓冲区,找到int#


问题是如何将变量
c=5
放在第二个括号内,使其成为
7

尽可能避免字符串连接。这是一个很好的用例


假设
c
保留一个整数的值作为开始(否则,
c+2
步骤失败)。

尽可能避免字符串串联。这是一个很好的用例


假设
c
持有一个整数的值作为开始(否则,
c+2
步骤失败)。

Python不会像某些语言那样自动将整数转换为其字符串表示形式。您需要使用
str()
format()
或f字符串显式地转换它。

Python不像某些语言那样自动将整数转换为字符串表示形式。您需要使用
str()
format()
或f字符串显式地转换它

c = 5
cmds.pointPosition(geo[0]+".cv[0][" + str(c) + "2]", w=True)
在Python中,不能连接str和int


在Python中,不能连接str和int。

Try
str(c)
format()
或f-string.Try
str(c)
format()
或f-string.Try。谢谢:)@Vladlenafanasajev如果有帮助的话,干杯。很棒的解释。谢谢:)@Vladlenafanasajev如果有帮助,干杯。
c = 5
cmds.pointPosition(geo[0]+".cv[0][" + str(c) + "2]", w=True)