Reputation: 75
Is this the best/most Pythonic way to initialize a boolean for this purpose?
if start == today:
b = date_time_obj <= start
else:
b = date_time_obj < start
if b:
do_something()
I can't think of another way to do it. Thanks in advance.
Upvotes: 0
Views: 47
Reputation: 81664
And if you really want to have some fun, try
b = (date_time_obj < start, date_time_obj <= start)[start == today]
Upvotes: 0
Reputation: 44283
Probably more common is:
b = date_time_obj <= start if start == today else date_time_obj < start
Upvotes: 1