more pythonic way
David Raymond
David.Raymond at tomtom.com
Mon Feb 11 15:15:29 EST 2019
My non-expert vote is for
if month is None:
month = datetime.date.today().month
Because you're checking for your default value, not whether the boolean version of what they did give you is True or False. It's explicit, it's not reliant on any __bool__() function implementations or overrides, etc.
-----Original Message-----
From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Felix Lazaro Carbonell
Sent: Monday, February 11, 2019 2:30 PM
To: python-list at python.org
Subject: more pythonic way
Hello to everyone:
Could you please tell me wich way of writing this method is more pythonic:
..
def find_monthly_expenses(month=None, year=None):
month = month or datetime.date.today()
..
Or it should better be:
...
if not month:
month = datetime.date.today()
..
Cheers,
Felix.
--
https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list