Python 如何将elif中给出的语句保存在变量中

Python 如何将elif中给出的语句保存在变量中,python,Python,如何将elif中给出的语句保存在变量中 比如: 我想将日期字保存在来自elif的变量中,您只需将其分配给变量,如: date = None ... elif 'date' in calendar: date = Date() elif 'date' in calendar: date = Date() 在添加剩余的if部件之前。问题是什么? elif 'date' in calendar: date = Date()

如何将elif中给出的语句保存在变量中 比如:


我想将日期字保存在来自elif的变量中,您只需将其分配给变量,如:

date = None

...

elif 'date' in calendar:
    date = Date()
elif 'date' in calendar:
     date = Date()

在添加剩余的if部件之前。

问题是什么?
elif 'date' in calendar:
     date = Date()