带变量的Python文本语法错误
“.itemid.”“带变量的Python文本语法错误,python,python-3.x,Python,Python 3.x,“.itemid.”“ 那里似乎有语法错误。如果要连接字符串,请使用+运算符: def postLoadItemUpdate(itemid): r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='".itemid."'") print(r.text) 如果要连接字符串,请使用+运算符: def postLoadItemUpdate(itemid): r = requests
那里似乎有语法错误。如果要连接字符串,请使用
+
运算符:
def postLoadItemUpdate(itemid):
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='".itemid."'")
print(r.text)
如果要连接字符串,请使用
+
运算符:
def postLoadItemUpdate(itemid):
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='".itemid."'")
print(r.text)
在Python中,使用
+
运算符进行字符串连接:
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'")
但是对于字符串连接,itemid
应该是字符串对象,否则需要使用str(itemid)
另一种选择是使用字符串格式,此处不需要类型转换:
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'"
在Python中,使用
+
运算符进行字符串连接:
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'")
但是对于字符串连接,itemid
应该是字符串对象,否则需要使用str(itemid)
另一种选择是使用字符串格式,此处不需要类型转换:
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'"
要连接字符串,必须使用
+
,如果itemid
不是字符串值,可能需要应用str
将其转换为字符串
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='{}'".format(itemid)
要连接字符串,必须使用
+
,如果itemid
不是字符串值,可能需要应用str
将其转换为字符串
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='{}'".format(itemid)
Python中的字符串连接的工作原理如下
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + str(itemid) + "'"
不是这样的:
s + itemId + t
Python中的字符串连接的工作原理如下
"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + str(itemid) + "'"
不是这样的:
s + itemId + t
或者,您也可以使用:
在您的特定用例中,正式的似乎更灵活,url更改几乎没有影响。或者,您也可以使用:
在您的特定用例中,formal似乎更灵活,url更改几乎没有影响。从何处开始:Python中的
“常量字符串”.itemid.“常量字符串2”
工作吗
您需要以不同的方式连接字符串。Python的交互模式是您的朋友:学会热爱它:
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id={0}".format(itemid))
这应该为您提供一个起点。从何处开始:在Python中,
“常量字符串”.itemid.“常量字符串2”
是否工作
您需要以不同的方式连接字符串。Python的交互模式是您的朋友:学会热爱它:
r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id={0}".format(itemid))
这应该给你一个起点