A function needs to at least have parentheses, even if it takes no parameters, so def test_year:
won't work. An if
statement can't be assigned to a variable. Instead, you could define a function that accepts curr_month
and list_early_fy
as parameters,
def test_year(curr_month, curr_year, list_early_fy):
if curr_month in list_early_fy:
print(int(curr_year)+1, curr_year)
And you'd call it via test_year(curr_month, curr_year, list_early_fy)
.
If you had a class that stored curr_month
, curr_year
, and list_early_fy
, you could reference those class variables:
class MyClass(object):
def __init__(self, curr_month, curr_year, list_early_fy):
self.curr_month = curr_month
self.curr_year = curr_year
self.list_early_fy = list_early_fy
def test_year():
if self.curr_month in self.list_early_fy:
print(int(self.curr_year)+1, self.curr_year)
c = MyClass(curr_month, curr_year, list_early_fy)
c.test_year()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…