category.is_parent = True if self.request.get('parentKey') is not None else category.is_parent = False Above is the code in which I am trying to write a if else in a single line and it is giving me this syntax error
SyntaxError: can't assign to conditional expression" But if I write it in following way it works fine
if self.request.get('parentKey') is not None: category.is_parent = True else: category.is_parent = False
category.is_parent = self.request.get('parentKey') != Nonex = a if condition else b, and you can chain multiple ones up too, likex = a if condition else b if condition2 else c<assignment>if condition else<assignment>'; the structure that's allowed is 'variable=<expression>' whereexpressionis of the form '<value1> if <condition> else <value2>'.