def cutB(sentence,dictB): result = [] sentenceLen = len(sentence) maxDictB = max([len(word) for word in dictB]) while sentenceLen > 0: word = '' for i in range(maxDictB, 0, -1): piece = sentence[sentenceLen - i:sentenceLen] if piece in dictB: word = piece result.append(word) sentenceLen -= i break if word is '': sentenceLen -= 1 result.append(sentence[sentenceLen]) print(result[::-1],end="")
<>:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
<>:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
C:\Users\41588\AppData\Local\Temp\ipykernel_4896\1394694574.py:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
if word is ”:
Python错误“SyntaxWarning: “is“ with a literal. Did you mean “==“?”
Python 3.8(或更高)下:
出现报错:
SyntaxWarning: “is” with a literal. Did you mean “==”?
解决方法:
将对应语句中is/is not用== 和 != 代替
原因:从 python 3.8 开始,使用 is 和 is not 运算符时,会抛出 SyntaxWarning 语句警告信息
125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/12274.html