【发布时间】:2021-01-22 18:39:54
【问题描述】:
我在下面定义了一些变量,我想用它们来定义一个变量。
today = datetime.today()
datem = str(datetime(today.year, today.month, 1))
curr_month = datem[5:7]
curr_year = datem[2:4]
list_early_fy = ['04', '05', '06', '07', '08', '09', '10', '11', '12']
然后我想使用这些来定义我正在使用的会计年度。我尝试了以下两种方法(第一种是我真正想要的),但都只是说“无效语法”。
test_year = if curr_month in list_early_fy:
print(int(curr_year)+1, curr_year)
def test_year:
if curr_month in list_early_fy:
print(int(curr_year)+1, curr_year)
最后,我想在我的代码的其他地方使用那个“test_year”变量。无论如何,关于如何使这项工作的任何建议?
【问题讨论】:
-
test year应该等于什么?你能举个例子吗 -
不清楚你想为
test_year分配什么值。如果你想要一个名为test_year的函数,你只是缺少括号:def test_year(): ...。
标签: python