Is it possible to do this on one line in Python?
if :
myList.append(\'myString\')
I have tried the ternary operator:>
You are basically asking for do_thing() if construct (which will throw SyntaxError, if ran). As I have discovered during research for (somewhat) similar question do_thing() if condition else None is as close as you can get (which is just another way to do ). So, to summarize this idea and other answers, here are your options:
if : myList.append('myString') — seems to be the least 'hacky' (and thus preferred) way and myList.append('myString') myList.append('myString') if else None