python中的“语句结束”字符串语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26428657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:27:45  来源:igfitidea点击:

"End of statement expected " string syntax error in python

pythonstring

提问by user61629

enter image description here

在此处输入图片说明

I have the following variable assignment:

我有以下变量赋值:

xpath_query="xpath='//a[@id="mylink"]'"

This is giving me an error in my pycharm editor and giving a syntax error when I run this code. What am I doing wrong?

这在我的 pycharm 编辑器中给我一个错误,并在我运行此代码时给出一个语法错误。我究竟做错了什么?

when I hold the cursor over the red squiggle it says:"end of statement expected "

当我将光标悬停在红色波浪线上方时,它会显示:“预期语句结束”

采纳答案by Anzel

You have double quotes inside your " " block. so it becomes:

你的 " " 块中有双引号。所以它变成:

"xpath='//a[@id=" <-- stick together with --> "]'"

"xpath='//a[@id=" <-- 和 --> "]'"

Hence it is a string syntax error.

因此它是一个字符串语法错误。

To include "inside " "block, you can use \to escape the character:

包括"里面" "块,你可以使用\逃脱字符:

xpath_query="xpath='//a[@id=\"mylink\"]'"