-1

I want to use one line to code the logic :

if the user email is None then user email equal to 'test@abc.com'.

I have tried:

user_email = 'test@abc.com' if user_email is None

Error:

             if user_email is None
                                 ^
       SyntaxError: invalid syntax

Any friend can help ?

William
  • 3,724
  • 9
  • 43
  • 76
  • ``` Though it had been delayed for several years by disagreements over syntax, an operator for a conditional expression in Python was approved as Python Enhancement Proposal 308 and was added to the 2.5 release in September 2006. Python's conditional operator differs from the common ?: operator in the order of its operands. The general form is: result = x if a > b else y This form invites considering x as the normal value and y as an exceptional case. ``` https://en.wikipedia.org/wiki/%3F:#Python – Axel Jacobsen Oct 24 '22 at 16:41
  • ```user_email = 'test@abc.com' if user_email is None else user_email``` – Lanbao Oct 25 '22 at 01:58

1 Answers1

-2
if len(email) == 0: email = "test@abc.com"

Hope it helps.

Poornaka
  • 180
  • 1
  • 13