That can be done much simpler considering that int(True) is 1 and int(False) is 0:
from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
More Related Contents:
- Does Python have a ternary conditional operator?
- Best way to return multiple values from a function? [closed]
- Is there a decorator to simply cache function return values?
- What are type hints in Python 3.5?
- How to add placeholder to an Entry in tkinter?
- How to change python version in anaconda spyder
- What is the return value of os.system() in Python?
- How do I pad a string with zeroes?
- Type hint for a function that returns only a specific set of values
- Anaconda vs. miniconda
- Confused about __str__ on list in Python [duplicate]
- Tensorflow: How to replace a node in a calculation graph?
- removing newlines from messy strings in pandas dataframe cells?
- How do I use cogs with discord.py?
- Python regex, matching pattern over multiple lines.. why isn’t this working?
- how to store a complex object in redis (using redis-py)
- How to make Python use CA certificates from Mac OS TrustStore?
- Updating OptionMenu from List
- Paramiko with continuous stdout
- When to use Serializer’s create() and ModelViewset’s perform_create()
- Notepad++ indentation messes up
- Keras misinterprets training data shape
- How to set the hue order in Seaborn plots
- Automatically creating directories with file output [duplicate]
- Equivalent to InnerHTML when using lxml.html to parse HTML
- How can I convert special characters in a string back into escape sequences?
- Why isn’t isnumeric working?
- Python- how to verify if a string ends with specific string?
- How to add custom field in ModelSerializer?
- Can I generate authentic random number with python?