user1592380
user1592380

Reputation: 36367

"End of statement expected " string syntax error in python

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?

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

Upvotes: 5

Views: 27360

Answers (1)

Anzel
Anzel

Reputation: 20583

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

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

Hence it is a string syntax error.

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

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

Upvotes: 4

Related Questions