if语句内的变量为什么在if外用不了

代码如下:
def OnCalSelChangedb(self, event):
self.days = 0

    cal = event.GetEventObject()
    datestr = cal.GetValue()  # 获取用户选择的日期 one

    beginyear = datestr.year   # 获取年份
    print(type(beginyear))

    beginmonth = str(int(datestr.month) + 1)
    print("beginmonth == %s" % beginmonth)  # 获取月份

    beginday = datestr.day  # 获取日

    big_month = [1, 3, 5, 7, 8, 10, 12]
    small_month = [4, 6, 9, 11]

    february = 0
    if beginyear % 4 == 0 and beginyear % 100 != 0:

        print("闰年")
        if beginmonth in big_month:
            february = 31
        elif beginmonth in small_month:
            february = 30
        elif beginmonth == 2:
            february = 29
    else:
        print("平年")
        if beginmonth in big_month:
            february = 31
        elif beginmonth in small_month:
            february = 30
        elif beginmonth == 2:
            february = 28
            
    print("february == %s" % february)
    self.days = february - beginday

不太明白,if内哪个变量不能使用

你要用哪个变量