![](/img/trans.png)
[英]Calculate age between two dates in year where one column has single date and other column has list of dates in python
[英]how to calculate age form list of dates in python
如何從列表中計算年齡。 這可能嗎?
name= ['Jonas','Miko','Jenelyn']
birthdate=['02/26/2000','12/02/2001','04/21/1999']
expected output:
student Jonas age is 20 y.o
student Miko age is 19 y.o
student Jenelyn age is 21 y.o
您需要適當地格式化日期,因此請研究日期時間日期 function 並從此處找出 go 的位置。
from datetime import date
today = date.today()
for n, bday in zip(name, birthdate):
age = (today - date(bday)).years
print("Student ", n, "age is ", age, "years old.")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.