Given this code
if account_id:
form = form.replace("<<ACCOUNT_ID>>", "<accountId>"+account_id+"</accountId>")
else:
form = form.replace("<<ACCOUNT_ID>>", "")
I was wondering if I could remove the else tag to make the code simpler:
account_id_tag = ""
if account_id:
account_id_tag = "<accountId>" + account_id + "</accountId>"
form = form.replace("<<ACCOUNT_ID>>", account_id_tag)
Or even using a ternary operator:
account_id_tag = "<accountId>" + account_id + "</accountId>" if account_id else ""
form = form.replace("<<ACCOUNT_ID>>", 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.