Conditionally replacing a placeholder in a form Given this code

if account_id:
    form = form.replace("&lt;&lt;ACCOUNT_ID&gt;&gt;", "&lt;accountId&gt;"+account_id+"&lt;/accountId&gt;")
else:
    form = form.replace("&lt;&lt;ACCOUNT_ID&gt;&gt;", "")


I was wondering if I could remove the else tag to make the code simpler:

account_id_tag = ""
if account_id:
    account_id_tag = "&lt;accountId&gt;" + account_id + "&lt;/accountId&gt;"
form = form.replace("&lt;&lt;ACCOUNT_ID&gt;&gt;", account_id_tag)


Or even using a ternary operator:

account_id_tag = "&lt;accountId&gt;" + account_id + "&lt;/accountId&gt;" if account_id else ""
form = form.replace("&lt;&lt;ACCOUNT_ID&gt;&gt;", account_id_tag)


But even the last one uses less lines, I have the sensation that the original option (with else) is easy to read and to understand, and this is very important for my point of view.
There is not "you choose this" rule in this context. But to be able to decide, you should take few elements in consideration:


Are you working on an existing code (which is not yours)? If so, it would be better to follow the philosophy of the existing code, or ask the project leader in case of doubt.
If this is a new project, then you could opt for the third option which was first proposed on PEP 0308 because, in general, typing less makes you less error prone.