python-3.x 如何单独保存列表值?

1wnzp6jl  于 2023-05-02  发布在  Python
关注(0)|答案(1)|浏览(110)

我如何将年、月、日与“今天”分开,并将它们保存在ex下。年=,月=,日=,?

import datetime
import time

#veriables

today = datetime.datetime.today()
print("Vpišite datum rojstva v zaporedju l-m-d")
leto = int(input("Leto: "))
mesec = int(input("Mesec: "))
dan = int(input("Dan: "))
 
list2 = [today]
one = list2[1]
two = list2[2]
three = list2[3]
print(list2, one, two, three)

我厌倦了这样做:How can I store each value from a list to multiple variables?

kse8i1jr

kse8i1jr1#

In [132]: today = dt.datetime.today()

In [133]: today
Out[133]: datetime.datetime(2023, 4, 25, 13, 39, 9, 875333)

In [134]: print("month =", today.month)
month = 4

In [135]: print("date =", today.day)
date = 25

In [136]: print("year =", today.year)
year = 2023

相关问题