Python 怎样用变量替换字符串?
发布网友
发布时间:2022-04-18 02:08
我来回答
共1个回答
热心网友
时间:2022-04-18 03:37
很简单
只要把
Xpath.replace(Xpath[35:36], num1)
改成
Xpath.replace(Xpath[35:36], str(num1))
以下是replace方法的详细说明
replace(...)
S.replace(old, new[, count]) -> string
Return a copy of string S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
参数只能是str类型
追问可是运行结果是这样的,我哪里有错误码?还是需要加载什么模块?
TypeError: 'str' object is not callable