python if one line without else code example
Example 1: python one line if without else
var = [exp] if [condition] else None
Example 2: one line if statement python without else
x = 1 > 0 # (True/False)
print(x)
#------------------------------------------
if (1 > 0): x = "something" # put any value
print(x)
Example 3: python one line if without else
>>> myList = []
>>> False and myList.append('myString')
False
>>> myList
[]
>>> True and myList.append('myString')
>>> myList
['myString']