title: Python "if" statement - if xpath is true
body: <p>im trying to code in python (very new to it) and need to check if an xpath is there then variable = the xpath but if not variable = string.</p>
  
  <p>An example is below</p>
  
  <pre><code>if tree.xpath('//*@id="page"]/div[1]/div/main/div/article/div/div[1]/section[2]/p[1]/span/text()') = true
  
  $value = tree.xpath('//*@id="page"]/div[1]/div/main/div/article/div/div[1]/section[2]/p[1]/span/text()')
  
  else
  
  $value = ''
  </code></pre>