1.传入多个参数(数字和字符串),如果是数字累加和,如果是字符串进行拼接。
def send_num(*args): """ :param args: 可遍长度的变量 :return: 返回连接后的字符串和计算后的数字 """ str1 = "" # 定义一个空字符串变量 num1 = 0 # 定义一个数字类型的变量 for i in args: # 循环遍历可遍长度的变量(元组tuple) if type(i) == str: # 判断是否是字符串类型 str1 += i # 通过+号来进行字符串拼接 else: num1 += i # 计算数字类型的数值的和 return str1, num1 # 返回拼接完成后和计算完成后的结果 if __name__ == '__main__': print(send_num(1, 2, 3, "hello", "world")) # 调用函数,并打印输出
输出:('helloworld', 6)
输入一个日期,判断该日期是否合法
输入一个日期,判断该日期是否合法;
def checkout_month(year, month, day): if (year % 4) == 0 and (year % 100) != 0 or (year % 400) == 0: if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12: if day <= 31: print("存在") else: print("不存在") elif month == 4 or month == 6 or month == 9 or month == 4: if day <= 30: print("存在") else: print("不存在") else: if day < 30: print("存在") else: print("不存在") else: if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12: if day <= 31: print("存在") else: print("不存在") elif month == 4 or month == 6 or month == 9 or month == 4: if day <= 30: print("存在") else: print("不存在") else: if day < 29: print("存在") else: print("不存在") if __name__ == '__main__': checkout_month(2014, 2, 29)
K:\自我学习\3月14日homework\venv\Scripts\python.exe K:/自我学习/3月14日homework/homework/homework05.py 不存在 Process finished with exit code 0