Python 首頁 Data Type

Function

參見 Python初學 函式 遞迴

def func_name(parameter)

          def check_leap_year(year):
              if (year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
                  print("閏年")
              else:
                  print("平年")
                  
          year = int(input())
          check_leap_year(year)        
        
          def check_leap_year(year):
              if (year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
                  return "閏年"
              else:
                  return "平年"
                  
          year = int(input())
          ret = check_leap_year(year)
          print(ret)
        
          def check_leap_year(year):
              if (year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
                  return True, "閏年"
              else:
                  return False, "平年"
                  
          year = int(input())
          is_leap, ret = check_leap_year(year)
          print(is_leap)
          print(ret)